結果

問題 No.39 桁の数字を入れ替え
ユーザー nemunemu
提出日時 2023-05-01 11:16:46
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 645 bytes
コンパイル時間 761 ms
コンパイル使用メモリ 67,312 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-20 10:59:40
合計ジャッジ時間 1,587 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

    string Ns = to_string(N);
    int maxdigit = 0;
    int maxidx = -1;
    for (int i = 0; i < (int)Ns.size(); ++i) {
        if (maxdigit <= Ns[i] - '0') {
            maxdigit = Ns[i] - '0';
            maxidx = i;
        }
    }
    // cout << maxdigit << " " << maxidx << endl;
    if (maxidx != -1) {
        for (int i = 0; i <= maxidx; ++i) {
            if (Ns[i] - '0' < Ns[maxidx] - '0') {
                swap(Ns[i], Ns[maxidx]);
                break;
            }
        }
    }
    

    cout << Ns << endl;
}
0