結果

問題 No.2385 Parse Integer with Radix
ユーザー flygonflygon
提出日時 2023-07-21 21:26:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 898 bytes
コンパイル時間 221 ms
コンパイル使用メモリ 81,692 KB
実行使用メモリ 62,048 KB
最終ジャッジ日時 2023-10-21 21:14:48
合計ジャッジ時間 1,467 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
55,600 KB
testcase_01 AC 53 ms
62,048 KB
testcase_02 AC 50 ms
62,048 KB
testcase_03 AC 54 ms
62,048 KB
testcase_04 AC 49 ms
62,048 KB
testcase_05 AC 44 ms
55,600 KB
testcase_06 AC 44 ms
55,600 KB
testcase_07 AC 45 ms
55,600 KB
testcase_08 AC 45 ms
55,600 KB
testcase_09 AC 46 ms
55,600 KB
testcase_10 AC 46 ms
55,600 KB
testcase_11 AC 51 ms
62,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0