結果

問題 No.256 桁の数字を入れ替え (2)
ユーザー RabbitCPRabbitCP
提出日時 2015-08-05 01:45:36
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 961 bytes
コンパイル時間 537 ms
コンパイル使用メモリ 74,120 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-09-02 20:19:08
合計ジャッジ時間 1,079 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 1 ms
4,368 KB
testcase_02 WA -
testcase_03 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.d(28): Deprecation: foreach: loop index implicitly converted from `size_t` to `int`

ソースコード

diff #

/*****************************
 Name         : Yoshitak
 Create Date  : 2015/06/05
 Program Name : main.d
 Problem No.  : 256
*****************************/

/*---------------------
 import
-----------------------*/
import std.stdio;
import std.string;
import std.conv;
import std.array;

/*---------------------
 main
-----------------------*/
int main(string[] args)
{
	//input
	uint[] num;
	string input;
	input = chomp(readln());
	
	//into the arry
	num.length = input.length;
	foreach(int i, char c; input){
		num[i] = to!int(c);
	}

	int tmp;
	
	if(num[0] > num[1]){
		//first change!!
		tmp = num[0];
		num[0] = num[1];
		num[1] = tmp;
	}
	
	//max is first!!
	int max = 0;
	for(int i=0; i<2; i++){
		max = i;
		//where is max!?
		for(int j=i+1; j<num.length; j++){
			if(num[max] <= num[j])	max = j;
		}
		
		//first change!!
		tmp = num[i];
		num[i] = num[max];
		num[max] = tmp;
	}
	
	//output
	foreach(int c; num){
		write(to!char(c));
	}
	return 0;
}
0