結果
問題 |
No.39 桁の数字を入れ替え
|
ユーザー |
|
提出日時 | 2016-11-25 11:23:01 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 589 bytes |
コンパイル時間 | 628 ms |
コンパイル使用メモリ | 58,012 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-27 11:08:29 |
合計ジャッジ時間 | 1,131 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 WA * 4 |
ソースコード
#include <iostream> #include <string> using namespace std; string N; char get_max(string N){ char max = 0; for (int i=0;i<N.length();i++) { char target = N[i]; max = (target > max) ? target : max; } return max; } string solve(string N, char max){ for (int i=0;i<N.length();i++) { if ((N[i]) != max) { for (int j=N.length()-1;j>=i+1;j--) { if (N[j] == max) { N[j] = N[i]; N[i] = max; return N; } } } } return N; } int main(){ cin >> N; char max = get_max(N); cout << solve(N, max) << endl; }