結果

問題 No.39 桁の数字を入れ替え
ユーザー nemunemu
提出日時 2023-05-01 11:44:41
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 532 bytes
コンパイル時間 648 ms
コンパイル使用メモリ 68,796 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-20 11:23:33
合計ジャッジ時間 1,415 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main() {
    int N;
    cin >> N;

    string Ns = to_string(N);
    for (int i = 0; i < (int)Ns.size(); ++i) {
        int max = Ns[i];
        int idx = i;
        for (int j = (int)Ns.size() - 1; j >= i + 1; --j) {
            if (max < Ns[j]) {
                max = Ns[j];
                idx = j;
            }
        }
        if (idx != i) {
            swap(Ns[i], Ns[idx]);
            break;
        }
    }
    
    cout << Ns << endl;
}
0