結果

問題 No.222 引き算と足し算
ユーザー 🍡yurahuna
提出日時 2016-05-04 13:44:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 41 ms / 1,000 ms
コード長 420 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 52,096 KB
最終ジャッジ日時 2024-11-15 22:10:51
合計ジャッジ時間 2,623 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

s = "#" + input()
t = ""
a = []
op = []
for i in range(1, len(s)):
    # 数字の直後の符号のみop
    if s[i] in ('+', '-') and s[i - 1].isdigit():
        op.append(s[i])
        a.append(t)
        t = ""
    else:
        t += s[i]
if t != "":
    a.append(t)

a = list(map(int, a))
ans = a[0]
for i in range(len(op)):
    if op[i] == '+':
        ans -= a[i + 1]
    else:
        ans += a[i + 1]
print(ans)
0