結果

問題 No.708 (+ー)の式
ユーザー mitsuo
提出日時 2018-08-20 14:52:28
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 520 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-11-25 02:55:58
合計ジャッジ時間 1,151 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(line):
    neg = False
    tmpneg = False
    sum = 0
    for i, c in enumerate(line):
        if c == "-":
            tmpneg = True

        if c == "(" and i > 0 and line[i - 1] == "-":
            neg = True
        elif c == ")":
            neg = False

        if c.isdigit():
            if tmpneg == neg:
                sum += int(c)
            else:
                sum -= int(c)

        if c != "-":
            tmpneg = False
    return sum

if __name__ == "__main__":
    print(solve(input()))
0