結果

問題 No.49 算数の宿題
ユーザー steek79steek79
提出日時 2015-10-15 23:44:07
言語 Python2
(2.7.18)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 492 bytes
コンパイル時間 58 ms
コンパイル使用メモリ 6,708 KB
実行使用メモリ 5,956 KB
最終ジャッジ日時 2023-08-24 17:26:59
合計ジャッジ時間 765 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,868 KB
testcase_01 AC 10 ms
5,936 KB
testcase_02 AC 10 ms
5,868 KB
testcase_03 AC 12 ms
5,924 KB
testcase_04 AC 11 ms
5,868 KB
testcase_05 AC 11 ms
5,944 KB
testcase_06 AC 10 ms
5,956 KB
testcase_07 AC 10 ms
5,856 KB
testcase_08 AC 10 ms
5,860 KB
testcase_09 AC 10 ms
5,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

S = raw_input()

def calc(ans, temp, next):
    if next == "+":
        ans += int(temp)
    elif next == "*":
        ans *= int(temp)
    return ans

ans = 0
temp = ""
next = "+"

for s in S:
    if s != "*" and s != "+":
        temp += s
        
    elif s == "*": 
        ans = calc(ans, temp, next)
        temp = ""
        next = "+"
        
    elif s == "+":
        ans = calc(ans, temp, next)
        temp = ""
        next = "*"
        
ans = calc(ans, temp, next)

print ans
0