結果
| 問題 | No.39 桁の数字を入れ替え | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-04-02 01:16:56 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 734 bytes | 
| コンパイル時間 | 1,554 ms | 
| コンパイル使用メモリ | 168,200 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-06-27 13:37:11 | 
| 合計ジャッジ時間 | 2,258 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 19 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    string n;
    cin >> n;
    //vector<char> chars(n.length());
    //rep(i, n.length()) chars[i] = n[i];
    rep(i, n.length()) {
        bool flg = false;
        int max_val = 0;
        int pos = 0;
        int current = stoi(""s + n[i]); 
        for(int j=i+1; j<n.length(); j++) {
            int val = stoi(""s + n[j]); 
            max_val = max(max_val, val);
            if(current < val) {
                flg = true;
                if(max_val == val) pos = j;
            }
            
        }
        if(flg) {
            swap(n[i], n[pos]);
            break;
        }
    }
    cout << n <<endl;
}
            
            
            
        