結果

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

ソースコード

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];
    }
    cout << endl;
}
0