結果

問題 No.39 桁の数字を入れ替え
ユーザー fiordfiord
提出日時 2015-06-01 19:19:03
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 792 bytes
コンパイル時間 611 ms
コンパイル使用メモリ 68,256 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-20 18:22:48
合計ジャッジ時間 1,612 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
	int n;	cin>>n;
	vector<int> data;
	for(int i=1;n/i>0;i=i*10){
		data.push_back((n/i)%10);
	}
	reverse(data.begin(),data.end());
	vector<int> compare(data);
	sort(compare.begin(),compare.end(),greater<int>());
	for(int i=0;i<(int)compare.size();i++){
		cout<<compare[i]<<" ";
	}
	cout<<endl;
	int a=0;
	while(data[a]==compare[a]&&a<(int)data.size())	a++;
	int b=a;
	for(int i=b+1;i<(int)data.size();i++){
		if(data[b]<=data[i])	b=i;
	}
	for(int i=0;i<(int)data.size();i++){
		cout<<data[i]<<" ";
	}	cout<<endl;
	if(data[a]!=data[b]){
		data[a]^=data[b];	data[b]^=data[a];	data[a]^=data[b];
	}
	for(vector<int>::iterator it=data.begin();it!=data.end();it++){
		cout<<*it;
	}
	cout<<endl;
	return 0;
}
0