結果

問題 No.2385 Parse Integer with Radix
ユーザー fairy_lettucefairy_lettuce
提出日時 2023-07-22 00:54:24
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 595 bytes
コンパイル時間 8,439 ms
コンパイル使用メモリ 158,012 KB
実行使用メモリ 177,936 KB
最終ジャッジ日時 2023-10-22 00:43:00
合計ジャッジ時間 10,713 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
32,536 KB
testcase_01 AC 65 ms
32,540 KB
testcase_02 AC 65 ms
32,540 KB
testcase_03 AC 66 ms
32,540 KB
testcase_04 AC 65 ms
32,540 KB
testcase_05 AC 66 ms
32,536 KB
testcase_06 AC 65 ms
32,536 KB
testcase_07 AC 66 ms
32,544 KB
testcase_08 AC 66 ms
32,552 KB
testcase_09 AC 66 ms
32,544 KB
testcase_10 AC 66 ms
32,552 KB
testcase_11 AC 66 ms
177,936 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (108 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.0/publish/

ソースコード

diff #

using System;
using System.Collections.Generic;

var q = int.Parse(Console.ReadLine());
var prefix = new Dictionary<string, int>()
{
	{ "0b", 2 },
	{ "0o", 8 },
	{ "0x", 16 }
};

// 8進数ない
// あと **リテラルでは** 0b, 0x を使えるのに文字列パースでは使えない
// なんやねんこの言語...
while (q-- > 0)
{
	var s = Console.ReadLine();
	var ok = false;
	foreach (var (key, value) in prefix)
	{
		if (s.StartsWith(key))
		{
			Console.WriteLine(Convert.ToInt64(s.Substring(2), value));
			ok = true;
		}
	}
	if (!ok)
	{
		Console.WriteLine(long.Parse(s));
	}
}
0