結果
| 問題 |
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 then
return s
end
local head = s:sub(1, 2)
if head == "0b" then
local mul = 1LL
local ans = 0LL
for i = #s, 3, -1 do
if s:sub(i, i) == "1" then
ans = ans + mul
end
mul = mul + mul
end
ans = tostring(ans):gsub("LL", "")
return ans
elseif head == "0o" then
local mul = 1LL
local ans = 0LL
for i = #s, 3, -1 do
local b = s:byte(i) - 48
ans = ans + mul * b
mul = mul * 8LL
end
ans = tostring(ans):gsub("LL", "")
return ans
elseif head == "0x" then
local mul = 1LL
local ans = 0LL
for i = #s, 3, -1 do
local b = s:byte(i) - 96
if b < 0 then
b = s:byte(i) - 48
else
b = s:byte(i) - 87
end
ans = ans + mul * b
mul = mul * 16
end
ans = tostring(ans):gsub("LL", "")
return ans
else
return s
end
end
for iq = 1, q do
print(solve())
end