結果
| 問題 |
No.2385 Parse Integer with Radix
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-07-21 21:26:52 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 53 ms / 2,000 ms |
| コード長 | 898 bytes |
| コンパイル時間 | 946 ms |
| コンパイル使用メモリ | 82,552 KB |
| 実行使用メモリ | 62,080 KB |
| 最終ジャッジ日時 | 2024-09-21 22:41:57 |
| 合計ジャッジ時間 | 1,342 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 11 |
ソースコード
import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline
from collections import defaultdict, deque, Counter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
from math import gcd
q = int(input())
d = {"b":2, "o":8, "x":16}
for i in range(q):
s = input().rstrip()
if len(s) == 1:
print(s)
continue
if s[1] not in {"b","o","x"}:
print(s)
continue
if s[1] == "b" or s[1] == "o":
n = 0
b = 1
for i in range(len(s) - 2):
n += b*int(s[-i-1])
b *= d[s[1]]
print(n)
else:
n = 0
b = 1
for i in range(len(s) - 2):
tmp = s[-i-1]
if ord("a")<= ord(tmp) <=ord("z"):
n += b*(ord(tmp)-ord("a") + 10)
else:
n += b*int(s[-i-1])
b *= d[s[1]]
print(n)