結果
問題 | No.927 Second Permutation |
ユーザー |
![]() |
提出日時 | 2020-08-29 07:33:00 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 10 ms / 2,000 ms |
コード長 | 447 bytes |
コンパイル時間 | 1,018 ms |
コンパイル使用メモリ | 74,936 KB |
最終ジャッジ日時 | 2025-01-13 20:00:51 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <iostream>#include <string>#include <algorithm>using namespace std;int main(){string X;cin >> X;sort(X.rbegin(), X.rend());if (X[1] == '0'){cout << -1 << endl;} else {int N = X.size();bool ok = false;for (int i = N - 2; i >= 0; i--){if (X[i] != '0' && X[i] != X[i + 1]){swap(X[i], X[i + 1]);ok = true;break;}}if (!ok){cout << -1 << endl;} else {cout << X << endl;}}}