結果

問題 No.39 桁の数字を入れ替え
コンテスト
ユーザー amtgjw
提出日時 2018-05-04 14:59:55
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 799 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 715 ms
コンパイル使用メモリ 94,580 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-03-16 08:59:34
合計ジャッジ時間 1,314 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

#define INF 		2000000007
#define MOD			1000003

#define MAX 		105

#define REP(i,n)	for(int i=0;i<(n);++i)
#define REPS(i,s,t)	for(int i=(s);i<(t);++i)

typedef unsigned int 			uint;
typedef unsigned long long int	ull;

int index(vector<int> &array,int search){
	for (int i=array.size()-1;i>=0;--i)
		if(array[i] == search)
			return i;
	return -1;
}

int main(){
	string str;cin >> str;

	vector<int> a,b;

	REP(i,str.size())
		a.push_back(str[i]-'0');
	b = a;
	sort(a.begin(),a.end(),greater<int>());

	for(int i=0;i<str.size();++i){
		if(a[i] != b[i]){
			int tmp = index(b,a[i]);
			swap(b[i],b[tmp]);
			break;
		}
	}//*/
	
	for(int t:b)
		cout << t;
	cout << endl;

	return 0;
}
0