結果

問題 No.2385 Parse Integer with Radix
ユーザー lloyzlloyz
提出日時 2023-07-21 21:26:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 685 bytes
コンパイル時間 205 ms
コンパイル使用メモリ 81,800 KB
実行使用メモリ 59,744 KB
最終ジャッジ日時 2023-10-21 21:13:54
合計ジャッジ時間 1,445 ms
ジャッジサーバーID
(参考情報)
judge9 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

for _ in range(int(input())):
    s = input()
    n = len(s)
    if n < 2:
        print(s)
        continue
    ans = 0
    if s[:2] == '0b':
        s = s[2:]
        n -= 2
        for i in range(n):
            ans += int(s[i]) * pow(2, n - 1 - i)
    elif s[:2] == '0o':
        s = s[2:]
        n -= 2
        for i in range(n):
            ans += int(s[i]) * pow(8, n - 1 - i)
    elif s[:2] == '0x':
        s = s[2:]
        n -= 2
        for i in range(n):
            if s[i].isdigit():
                ans += int(s[i]) * pow(16, n - 1 - i)
            else:
                ans += (ord(s[i]) - ord('a') + 10) * pow(16, n - 1 - i)
    else:
        ans = s
    print(ans)
0