結果

問題 No.49 算数の宿題
ユーザー nanaenanae
提出日時 2017-02-16 17:54:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 26 ms / 5,000 ms
コード長 542 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 10,856 KB
実行使用メモリ 9,264 KB
最終ジャッジ日時 2023-08-24 17:35:52
合計ジャッジ時間 979 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
9,084 KB
testcase_01 AC 26 ms
9,212 KB
testcase_02 AC 26 ms
9,076 KB
testcase_03 AC 25 ms
9,164 KB
testcase_04 AC 24 ms
9,264 KB
testcase_05 AC 23 ms
9,080 KB
testcase_06 AC 23 ms
9,204 KB
testcase_07 AC 24 ms
9,252 KB
testcase_08 AC 24 ms
9,168 KB
testcase_09 AC 23 ms
9,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import re

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    S = input()
    nums = re.split(r'[*+]', S)
    nums = list(map(int, nums))
    ops = [op for op in S if not op.isdigit()]
    ans = nums[0]

    for i, op in enumerate(ops, start=1):
        if op == '*':
            ans += nums[i]
        else:
            ans *= nums[i]

    print(ans)

if __name__ == '__main__':
    solve()
0