結果

問題 No.708 (+ー)の式
コンテスト
ユーザー ntuda
提出日時 2024-02-10 01:40:23
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 876 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 263 ms
コンパイル使用メモリ 85,032 KB
実行使用メモリ 53,784 KB
最終ジャッジ日時 2026-04-15 06:18:05
合計ジャッジ時間 1,648 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

S = input()
N = len(S)
i = 0
j = 0
op = {"+","-"}
tmp1 = 0
op1 = 1
while i + j < N:
    if S[i+j] == "(":
        tmp2 = 0
        op2 = 1
        j += 1
        while S[i+j] != ")":
            if S[i + j] not in op:
                if op2 == 1:
                    tmp2 += int(S[i + j])
                else:
                    tmp2 -= int(S[i + j])
            else:
                if S[i + j] == "+":
                    op2 = 1
                else:
                    op2 = 0
            j += 1
        if op1 == 1:
            tmp1 += tmp2
        else:
            tmp1 -= tmp2

    else:
        if S[i+j] not in op:
            if op1 == 1:
                tmp1 += int(S[i+j])
            else:
                tmp1 -= int(S[i+j])
        else:
            if S[i+j] == "+":
                op1 = 1
            else:
                op1 = 0
    i += 1
print(tmp1)
0