結果

問題 No.2385 Parse Integer with Radix
ユーザー nikoro256nikoro256
提出日時 2023-07-21 21:31:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 535 bytes
コンパイル時間 191 ms
コンパイル使用メモリ 81,664 KB
実行使用メモリ 59,868 KB
最終ジャッジ日時 2023-10-21 21:21:40
合計ジャッジ時間 1,184 ms
ジャッジサーバーID
(参考情報)
judge12 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,412 KB
testcase_01 AC 41 ms
59,864 KB
testcase_02 AC 37 ms
59,864 KB
testcase_03 AC 38 ms
59,864 KB
testcase_04 AC 37 ms
59,864 KB
testcase_05 AC 34 ms
53,412 KB
testcase_06 AC 33 ms
53,412 KB
testcase_07 AC 37 ms
59,864 KB
testcase_08 AC 36 ms
59,868 KB
testcase_09 AC 33 ms
53,412 KB
testcase_10 AC 38 ms
59,868 KB
testcase_11 AC 41 ms
59,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

Q=int(input())
for i in range(Q):
    S=input()
    d=1
    if len(S)<2:
        print(S)
        continue
    if S[:2]=='0b':
        d=2
    elif S[:2]=='0o':
        d=8
    elif S[:2]=='0x':
        d=16
    else:
        print(S)
        continue
    exp=1
    ans=0
    s={'a','b','c','d','e','f'}
    dic={'a':10,'b':11,'c':12,'d':13,'e':14,'f':15}
    for j in range(len(S)-1,1,-1):
        k=0
        if S[j] in s:
            k=dic[S[j]]
        else:
            k=int(S[j])
        ans+=exp*k
        exp*=d
    print(ans)
0