結果

問題 No.164 ちっちゃくないよ!!
ユーザー 綾地寧々綾地寧々
提出日時 2015-05-16 19:55:38
言語 PHP
(8.3.4)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 1,025 bytes
コンパイル時間 5,212 ms
コンパイル使用メモリ 30,692 KB
実行使用メモリ 31,608 KB
最終ジャッジ日時 2024-04-21 15:25:19
合計ジャッジ時間 6,108 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
31,436 KB
testcase_01 AC 35 ms
31,364 KB
testcase_02 AC 36 ms
31,608 KB
testcase_03 AC 36 ms
31,508 KB
testcase_04 AC 35 ms
31,364 KB
testcase_05 AC 36 ms
31,364 KB
testcase_06 AC 38 ms
31,516 KB
testcase_07 AC 37 ms
31,236 KB
testcase_08 AC 37 ms
31,296 KB
testcase_09 AC 36 ms
31,376 KB
testcase_10 AC 35 ms
31,140 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php

$nums = trim(fgets(STDIN));
$min_value = 0;
$min_text = "";
$min_base = 0;
for ( $i=0; $i<$nums; $i++ ) {
	$input = trim(fgets(STDIN));
	$base = get_base($input);
	$value = base_convert($input, $base, 10);
	if ( ($i == 0) || ($min_value > $value) ) {
		$min_value = $value;
		$min_text = $input;
		$min_base = $base;
	}
}
$min_text_len = strlen($min_text);
$gmp_num = gmp_init(0);
for ( $i=0; $i<$min_text_len; $i++ ) {
	$text = substr($min_text, 0, 1);
	$min_text = substr($min_text, 1);
	$gmp_num = gmp_mul($gmp_num, gmp_init($min_base));
	$gmp_num = gmp_add($gmp_num, gmp_init(base_convert($text, $min_base, 10)));
}
echo gmp_strval($gmp_num).PHP_EOL;

function get_base ( $string ) {
	$count = count_chars($string,1);
	$key = ord('Z');
	while ( array_key_exists($key,$count) !== TRUE ) {
		if ( $key == ord('A') ) {
			$key = ord('9');
		}
		else {
			$key--;
		}
	}
	if ( $key >= ord('A') ) {
		$base = $key - 54;
	}
	else if ( $key >= ord('1') ) {
		$base = $key - 47;
	}
	else {
		$base = 2;
	}
	return $base;
}
0