結果

問題 No.49 算数の宿題
ユーザー brthyyjpbrthyyjp
提出日時 2021-01-08 21:01:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 74 ms / 5,000 ms
コード長 751 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 86,944 KB
実行使用メモリ 71,464 KB
最終ジャッジ日時 2023-08-24 17:49:14
合計ジャッジ時間 1,710 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,432 KB
testcase_01 AC 70 ms
71,252 KB
testcase_02 AC 70 ms
71,464 KB
testcase_03 AC 70 ms
71,252 KB
testcase_04 AC 74 ms
71,280 KB
testcase_05 AC 73 ms
71,396 KB
testcase_06 AC 73 ms
71,176 KB
testcase_07 AC 73 ms
71,232 KB
testcase_08 AC 72 ms
71,352 KB
testcase_09 AC 74 ms
71,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

s = str(input())
S = []
temp = []
for c in s:
    if c != '*' and c!= '+':
        temp.append(c)
    else:
        S.append(''.join(temp))
        S.append(c)
        temp = []
else:
    if temp:
        S.append(''.join(temp))

stack = []
for c in S:
    if not stack:
        stack.append(c)
    else:
        if c != '*' and c != '+':
            if stack[-1] != '*' and stack[-1] != '+':
                stack[-1] += c
            elif stack[-1] == '*':
                stack.pop()
                x = stack.pop()
                stack.append(str(int(x)+int(c)))
            else:
                stack.pop()
                x = stack.pop()
                stack.append(str(int(x)*int(c)))
        else:
            stack.append(c)
print(*stack)
0