結果

問題 No.927 Second Permutation
ユーザー kya_ski
提出日時 2019-11-22 21:50:30
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 521 bytes
コンパイル時間 1,730 ms
コンパイル使用メモリ 176,344 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-11 03:20:04
合計ジャッジ時間 2,706 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 22 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    string s;
    cin >> s;
    int n = s.length();
    set<char> c;
    for (int i = 0; i < n; i++) {
        if (s[i] != 0) c.insert(s[i]);
    }
    sort(s.begin(), s.end());

    if (c.size() > 1) {
        for (int i = 1; i < n; i++) {
            if (s[i] != '0') {
                swap(s[i], s[i-1]);
                break;
            }
        }
        reverse(s.begin(), s.end());
    }
    cout << ((c.size() > 1) ? s : "-1") << endl;
    return 0;
}
0