結果

問題 No.927 Second Permutation
ユーザー kikage
提出日時 2020-03-23 19:31:03
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 470 bytes
コンパイル時間 1,219 ms
コンパイル使用メモリ 60,916 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-26 17:54:07
合計ジャッジ時間 3,059 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    string str;
    cin >> str;
    sort(str.begin(),str.end());
    reverse(str.begin(),str.end());
    bool flag=false;
    for(int pos=str.size()-1;pos>0;pos--){
        if(str.at(pos)!=str.at(pos-1)){
            swap(str.at(pos),str.at(pos-1));
            flag=true;break;
        }
    }
    if(flag && str.at(0)!='0')cout << str << endl;
    else cout << "-1" << endl;
    return 0;
}
0