結果

問題 No.927 Second Permutation
ユーザー MJXzkibvOFVxZkxMJXzkibvOFVxZkx
提出日時 2019-11-22 22:31:54
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 501 bytes
コンパイル時間 1,731 ms
コンパイル使用メモリ 161,236 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-11 04:15:05
合計ジャッジ時間 2,448 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    string s,copy;
    cin>>s;
    copy=s;
    int si=s.size(),count=0;
    sort(s.begin(),s.end());
    for(int i=si-1;i>=0;i--){
        if(s[i]=='0'){
            count++;
        }
    }
    if(si-1==count || copy==s){
        cout<<-1<<'\n';
    }
    else{
if(count!=0){
    swap(s[count],s[count-1]);
}
else{
swap(s[0],s[1]);
}
        for(int i=si-1;i>=0;i--){
            cout<<s[i];
        }
        cout<<'\n';
    }
	return 0;
}
0