結果

問題 No.2385 Parse Integer with Radix
ユーザー 👑 MizarMizar
提出日時 2023-06-23 12:26:11
言語 Ruby
(3.3.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 361 bytes
コンパイル時間 39 ms
コンパイル使用メモリ 11,236 KB
実行使用メモリ 15,404 KB
最終ジャッジ日時 2023-09-15 17:07:11
合計ジャッジ時間 1,956 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
15,296 KB
testcase_01 AC 89 ms
15,156 KB
testcase_02 AC 83 ms
15,260 KB
testcase_03 AC 81 ms
15,148 KB
testcase_04 AC 87 ms
15,404 KB
testcase_05 AC 80 ms
15,148 KB
testcase_06 AC 79 ms
15,248 KB
testcase_07 AC 81 ms
15,300 KB
testcase_08 AC 82 ms
15,168 KB
testcase_09 AC 81 ms
15,020 KB
testcase_10 AC 82 ms
15,168 KB
testcase_11 AC 82 ms
15,064 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

gets.to_i.times do
	s = gets.chomp
	b = 10
	if s[0,2] == "0b"
		s.slice!(0,2)
		b = 2
	elsif s[0,2] == "0o"
		s.slice!(0,2)
		b = 8
	elsif s[0,2] == "0x"
		s.slice!(0,2)
		b = 16
	end
	n = 0
	s.chars.each do |c|
		if c >= "0" && c <= "9"
			n = n * b + (c.ord - "0".ord)
		elsif c >= "a" && c <= "z"
			n = n * b + (c.ord - "a".ord + 10)
		end
	end
	puts n
end
0