結果

問題 No.39 桁の数字を入れ替え
ユーザー nemunemu
提出日時 2024-01-14 05:55:35
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 595 bytes
コンパイル時間 2,656 ms
コンパイル使用メモリ 119,808 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-28 01:56:53
合計ジャッジ時間 1,504 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

// No.39 桁の数字を入れ替え
#include <iostream>
#include <string>
using namespace std;

int main() {
    string N;
    cin >> N;
    for (int i = 0; i < N.size(); ++i) {
        int x = -1;
        int cur = N[i];
        for (int j = i + 1; j < N.size(); ++j) {
            if (cur < N[j]) {
                x = j;
                cur = N[j];
            } else if (cur == N[j] && x != -1) {
                x = j;
            }
        }
        if (x != -1) {
            swap(N[i], N[x]);
            cout << N << endl;
            return 0;
        }
    }
    cout << N << endl;
}
0