結果

問題 No.927 Second Permutation
ユーザー leaf_1415
提出日時 2019-03-12 04:35:23
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 402 bytes
コンパイル時間 640 ms
コンパイル使用メモリ 61,816 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-02 09:19:00
合計ジャッジ時間 2,069 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int n;
string s;

int main(void)
{
	cin >> s;
	sort(s.rbegin(), s.rend());
	n = s.size();
	
	if(s[0] == s[n-1]){
		cout << -1 << endl;
		return 0;
	}
	for(int i = n-1; i >= 0; i--){
		if(s[i] != s[n-1]){
			swap(s[i], s[i+1]);
			break;
		}
	}
	if(s[0] == '0') cout << -1 << endl;
	else cout << s << endl;
	
	return 0;
}
0