結果
問題 | No.2385 Parse Integer with Radix |
ユーザー |
👑 |
提出日時 | 2023-06-22 18:50:35 |
言語 | JavaScript (node v23.5.0) |
結果 |
AC
|
実行時間 | 72 ms / 2,000 ms |
コード長 | 968 bytes |
コンパイル時間 | 30 ms |
コンパイル使用メモリ | 6,944 KB |
実行使用メモリ | 39,680 KB |
最終ジャッジ日時 | 2024-07-02 19:20:41 |
合計ジャッジ時間 | 1,486 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 11 |
ソースコード
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()); });