結果

問題 No.708 (+ー)の式
ユーザー aporo_eeicaporo_eeic
提出日時 2018-07-06 01:44:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 409 bytes
コンパイル時間 358 ms
コンパイル使用メモリ 10,552 KB
実行使用メモリ 7,896 KB
最終ジャッジ日時 2023-09-13 18:03:49
合計ジャッジ時間 1,314 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,872 KB
testcase_01 AC 14 ms
7,744 KB
testcase_02 AC 14 ms
7,824 KB
testcase_03 AC 16 ms
7,820 KB
testcase_04 AC 15 ms
7,880 KB
testcase_05 AC 15 ms
7,752 KB
testcase_06 AC 15 ms
7,800 KB
testcase_07 AC 15 ms
7,740 KB
testcase_08 AC 15 ms
7,880 KB
testcase_09 AC 14 ms
7,784 KB
testcase_10 AC 15 ms
7,796 KB
testcase_11 AC 14 ms
7,896 KB
testcase_12 AC 15 ms
7,784 KB
testcase_13 AC 15 ms
7,744 KB
testcase_14 AC 15 ms
7,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

data = input().strip()
calc_flag = [1]
ans = [0]
for c in data:
    if(c == "("):
        ans.append(0)
        calc_flag.append(1)
    elif(c == ")"):
        tmp = ans[-1]
        ans.pop()
        calc_flag.pop()
        ans[-1] += tmp*calc_flag[-1]
    elif(c == "+"):
        calc_flag[-1] = 1
    elif(c == "-"):
        calc_flag[-1] = -1
    else:
        ans[-1] += calc_flag[-1]*int(c)
print(ans[0])
0