結果

問題 No.927 Second Permutation
ユーザー ohreitetsu
提出日時 2019-11-22 22:18:16
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 586 bytes
コンパイル時間 771 ms
コンパイル使用メモリ 75,008 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-11 03:59:57
合計ジャッジ時間 1,846 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char* argv[])
{
	string S;
	cin>>S;
	vector<char> X;
	size_t strLen=S.length();
	for (int i=0;i<S.length();i++){
		X.push_back(S[i]);
	}
	sort(X.begin(),X.end());
	bool bSwap=false;
	for (int i=0;i<strLen-1;i++){
		if (X[i]!=X[i+1]){
			swap(X[i],X[i+1]);
			bSwap=true;
			break;
		}
	}
	if (bSwap){
		if (X[strLen-1]=='0'){
			cout<<-1<<endl;
			return 0;
		}
		for (int i=strLen-1;i>=0;i--){
			cout<<X[i];
		}
		cout<<endl;
	}else{
		cout<<-1<<endl;
	}
	return 0;
}
0