結果

問題 No.927 Second Permutation
ユーザー trineutron
提出日時 2020-12-21 14:00:32
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 483 bytes
コンパイル時間 2,006 ms
コンパイル使用メモリ 199,200 KB
最終ジャッジ日時 2025-01-17 05:32:58
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    sort(s.rbegin(), s.rend());
    for (int i = n - 2; i >= 0; i--) {
        if (s.at(i) != s.at(i + 1)) {
            swap(s.at(i), s.at(i + 1));
            break;
        }
        if (i == 0) {
            cout << -1 << endl;
            return 0;
        }
    }
    if (s.at(0) == '0') {
        cout << -1 << endl;
        return 0;
    }
    cout << s << endl;
}
0