結果
| 問題 | No.39 桁の数字を入れ替え | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2015-05-20 21:02:02 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 567 bytes | 
| コンパイル時間 | 557 ms | 
| コンパイル使用メモリ | 57,984 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2024-10-02 06:21:49 | 
| 合計ジャッジ時間 | 1,114 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 19 | 
ソースコード
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
	string str;
	cin >> str;
	int n = (int)str.size();
	int x = 0;
	while(x < n){
		int maxIdx = n;
		for(int i = n - 1; i > x; i--){
			if(str[i] > str[maxIdx]){
				maxIdx = i;
			}
		}
		
		bool isSwapped = false;
		for(int i = 0; i < n; i++){
			if(!isSwapped && str[maxIdx] > str[i] && maxIdx > i){
				swap(str[maxIdx], str[i]);
				isSwapped = true;
			}
		}
		if(isSwapped) break;
		else x++;
	}
	long long ans = atoll(str.c_str());
	cout << ans << endl;
	return 0;
}
            
            
            
        