結果
問題 | No.2385 Parse Integer with Radix |
ユーザー |
👑 |
提出日時 | 2023-07-23 21:18:44 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,006 bytes |
コンパイル時間 | 338 ms |
コンパイル使用メモリ | 6,940 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-25 00:42:54 |
合計ジャッジ時間 | 883 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 11 |
ソースコード
local q = io.read("*n", "*l")local function solve()local s = io.read()if #s == 1 thenreturn sendlocal head = s:sub(1, 2)if head == "0b" thenlocal mul = 1LLlocal ans = 0LLfor i = #s, 3, -1 doif s:sub(i, i) == "1" thenans = ans + mulendmul = mul + mulendans = tostring(ans):gsub("LL", "")return anselseif head == "0o" thenlocal mul = 1LLlocal ans = 0LLfor i = #s, 3, -1 dolocal b = s:byte(i) - 48ans = ans + mul * bmul = mul * 8LLendans = tostring(ans):gsub("LL", "")return anselseif head == "0x" thenlocal mul = 1LLlocal ans = 0LLfor i = #s, 3, -1 dolocal b = s:byte(i) - 96if b < 0 thenb = s:byte(i) - 48elseb = s:byte(i) - 87endans = ans + mul * bmul = mul * 16endans = tostring(ans):gsub("LL", "")return anselsereturn sendendfor iq = 1, q doprint(solve())end