結果

問題 No.39 桁の数字を入れ替え
ユーザー 綾地寧々綾地寧々
提出日時 2015-07-25 14:14:20
言語 PHP
(8.3.4)
結果
AC  
実行時間 43 ms / 5,000 ms
コード長 505 bytes
コンパイル時間 2,736 ms
コンパイル使用メモリ 32,148 KB
実行使用メモリ 32,532 KB
最終ジャッジ日時 2024-04-10 05:01:19
合計ジャッジ時間 3,613 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
32,404 KB
testcase_01 AC 40 ms
32,276 KB
testcase_02 AC 40 ms
32,404 KB
testcase_03 AC 40 ms
32,144 KB
testcase_04 AC 41 ms
32,404 KB
testcase_05 AC 41 ms
32,404 KB
testcase_06 AC 40 ms
32,404 KB
testcase_07 AC 40 ms
32,404 KB
testcase_08 AC 40 ms
32,276 KB
testcase_09 AC 40 ms
32,528 KB
testcase_10 AC 41 ms
32,404 KB
testcase_11 AC 40 ms
32,272 KB
testcase_12 AC 41 ms
32,020 KB
testcase_13 AC 41 ms
32,404 KB
testcase_14 AC 41 ms
32,404 KB
testcase_15 AC 40 ms
32,532 KB
testcase_16 AC 43 ms
32,404 KB
testcase_17 AC 40 ms
32,400 KB
testcase_18 AC 41 ms
32,140 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