結果

問題 No.2385 Parse Integer with Radix
ユーザー 👑 MizarMizar
提出日時 2023-06-22 18:50:35
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 968 bytes
コンパイル時間 63 ms
コンパイル使用メモリ 5,212 KB
実行使用メモリ 42,724 KB
最終ジャッジ日時 2023-09-15 17:07:03
合計ジャッジ時間 1,795 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
42,216 KB
testcase_01 AC 88 ms
42,472 KB
testcase_02 AC 87 ms
42,408 KB
testcase_03 AC 85 ms
42,516 KB
testcase_04 AC 84 ms
42,724 KB
testcase_05 AC 82 ms
42,376 KB
testcase_06 AC 81 ms
42,180 KB
testcase_07 AC 83 ms
42,540 KB
testcase_08 AC 84 ms
42,668 KB
testcase_09 AC 82 ms
42,608 KB
testcase_10 AC 82 ms
42,412 KB
testcase_11 AC 82 ms
42,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

let l = require("fs").readFileSync("/dev/stdin", "utf8").split("\n");
const codePoint_0 = '0'.codePointAt(0);
const codePoint_a = 'a'.codePointAt(0);
l.slice(1, parseInt(l[0]) + 1).forEach(s=>{
	let n = BigInt(0);
	switch (s.slice(0, 2)) {
		case '0b':
			// 2進数
			Array.from(s.slice(2)).forEach(c => {
				n = n * 2n + BigInt(c.codePointAt(0) - codePoint_0);
			});
			break;
		case '0o':
			// 8進数
			Array.from(s.slice(2)).forEach(c => {
				n = n * 8n + BigInt(c.codePointAt(0) - codePoint_0);
			});
			break;
		case '0x':
			// 16進数
			Array.from(s.slice(2)).forEach(c => {
				if (c >= '0' && c <= '9') {
					n = n * 16n + BigInt(c.codePointAt(0) - codePoint_0);
				} else if (c >= 'a' && c <= 'z') {
					n = n * 16n + BigInt(c.codePointAt(0) - codePoint_a + 10);
				}
			});
			break;
		default:
			// 10進数
			Array.from(s).forEach(c => {
				n = n * 10n + BigInt(c.codePointAt(0) - codePoint_0);
			});
	}
	console.log(n.toString());
});
0