結果

問題 No.39 桁の数字を入れ替え
ユーザー 綾地寧々綾地寧々
提出日時 2015-07-25 14:14:20
言語 PHP
(7.2.24)
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 505 bytes
コンパイル時間 1,340 ms
コンパイル使用メモリ 18,620 KB
実行使用メモリ 19,008 KB
最終ジャッジ日時 2023-07-25 12:14:54
合計ジャッジ時間 2,740 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
18,928 KB
testcase_01 AC 17 ms
18,668 KB
testcase_02 AC 16 ms
18,812 KB
testcase_03 AC 16 ms
18,832 KB
testcase_04 AC 16 ms
18,880 KB
testcase_05 AC 17 ms
18,948 KB
testcase_06 AC 17 ms
18,824 KB
testcase_07 AC 17 ms
18,900 KB
testcase_08 AC 16 ms
18,944 KB
testcase_09 AC 18 ms
18,880 KB
testcase_10 AC 18 ms
18,804 KB
testcase_11 AC 17 ms
18,804 KB
testcase_12 AC 17 ms
18,920 KB
testcase_13 AC 17 ms
18,888 KB
testcase_14 AC 17 ms
18,800 KB
testcase_15 AC 17 ms
19,008 KB
testcase_16 AC 18 ms
18,940 KB
testcase_17 AC 17 ms
18,916 KB
testcase_18 AC 17 ms
18,804 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
$n = trim(fgets(STDIN));
$n_array = array();
// 1桁ずつ分解する
for ( $i=0; $i<strlen($n); $i++ ) {
	$n_array[] = intval(substr($n,$i,1));
}
for ( $max=9; $max>0; $max-- ) {
	for ( $i=count($n_array)-1; $i>=0; $i-- ) {
		if ( $n_array[$i] == $max ) {
			for ( $j=0; $j<$i; $j++ ) {
				if ( $n_array[$j] < $n_array[$i] ) {
					swap($n_array[$j], $n_array[$i]);
					break 3;
				}
			}
		}
	}
}
echo implode("", $n_array).PHP_EOL;

function swap (&$a, &$b) {
	$t = $a;
	$a = $b;
	$b = $t;
}
0