結果

問題 No.708 (+ー)の式
ユーザー ttrttr
提出日時 2020-02-10 19:59:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 478 bytes
コンパイル時間 251 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 9,984 KB
最終ジャッジ日時 2024-04-08 13:12:34
合計ジャッジ時間 1,535 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
9,984 KB
testcase_01 AC 31 ms
9,984 KB
testcase_02 AC 31 ms
9,984 KB
testcase_03 AC 31 ms
9,984 KB
testcase_04 AC 30 ms
9,984 KB
testcase_05 AC 30 ms
9,984 KB
testcase_06 AC 30 ms
9,984 KB
testcase_07 AC 29 ms
9,984 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 30 ms
9,984 KB
testcase_14 AC 30 ms
9,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

S = input()

i = 0
ans = 0
sgn = 1
flag = True
while i < len(S):
    if S[i] == "+" and flag:
        i += 1
        continue
    elif S[i] == "+":
        sgn = -1
    elif S[i] == "-" and flag:
        sgn = -1
    elif S[i] == "-":
        sgn = 1
    elif S[i] == "(" and i > 0 and S[i-1] == "-":
        flag = False
    elif S[i] == "(":
        i += 1
        continue
    elif S[i] == ")":
        flag = True
    else:
        ans += sgn*int(S[i])
    i += 1
print(ans)
0