結果
問題 | No.927 Second Permutation |
ユーザー |
|
提出日時 | 2019-11-22 22:23:09 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 428 bytes |
コンパイル時間 | 1,712 ms |
コンパイル使用メモリ | 161,240 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-11 04:05:23 |
合計ジャッジ時間 | 2,359 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h>using namespace std;int main(){string x;cin >> x;sort(x.begin(), x.end(), greater<char>());int n = x.size();if(x[0] == x[n-1] || x[1] == '0'){cout << -1 << endl;return 0;}int i;for(i = n-1;i >= 0;i--){if(x[n-1] != x[i]){swap(x[i], x[i+1]);break;}}cout << x << endl;return 0;}