結果

問題 No.49 算数の宿題
ユーザー yansi819
提出日時 2024-05-26 12:51:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 41 ms / 5,000 ms
コード長 577 bytes
コンパイル時間 360 ms
コンパイル使用メモリ 82,028 KB
実行使用メモリ 52,224 KB
最終ジャッジ日時 2024-12-20 20:15:16
合計ジャッジ時間 1,452 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

def myeval(S):
    op = ""
    num = ""
    res = 0
    for c in S:
        if c != "+" and c != "*":
            num += c
        else:
            if op == "":
                res = int(num)
            else:
                if op == "+":
                    res += int(num)
                else:
                    res *= int(num)
            num = ""
            op = c
    if op == "+":
        res += int(num)
    else:
        res *= int(num)
    return res

S = input().rstrip()
S = S.replace("*", "%")
S = S.replace("+", "*")
S = S.replace("%", "+")
print(myeval(S))
0