結果

問題 No.927 Second Permutation
ユーザー kyoprouno
提出日時 2019-11-22 21:51:13
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 514 bytes
コンパイル時間 1,693 ms
コンパイル使用メモリ 174,120 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-11 03:20:57
合計ジャッジ時間 2,787 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 8 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main(){
    string s;
    cin >> s;
    vector<int> a(s.length());
    for(int i=0;i<s.length();i++){
        a[i]=s[i]-'0';
    }
    sort(a.rbegin(),a.rend());
    if(a[s.length()-1]==a[s.length()-2]){
        cout << -1 << endl;
        return 0;
    }
    if(s.length()==2 && a[s.length()-1]=='0'){
        cout << -1 << endl;
        return 0;
    }
    swap(a[s.length()-1],a[s.length()-2]);
    for(int i=0;i<s.length();i++){
        cout << a[i];
    }
}
0