結果
| 問題 | No.708 (+ー)の式 | 
| コンテスト | |
| ユーザー |  とりゐ | 
| 提出日時 | 2023-06-06 10:37:15 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 40 ms / 2,000 ms | 
| コード長 | 496 bytes | 
| コンパイル時間 | 311 ms | 
| コンパイル使用メモリ | 82,652 KB | 
| 実行使用メモリ | 52,352 KB | 
| 最終ジャッジ日時 | 2024-12-29 08:22:31 | 
| 合計ジャッジ時間 | 1,674 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 12 | 
ソースコード
def expr(s):
  global i
  res=term(s)
  while i<len(s):
    if s[i]=='+':
      i+=1
      res+=term(s)
    elif s[i]=='-':
      i+=1
      res-=term(s)
    else:
      break
  return res
def term(s):
  return factor(s)
def factor(s):
  global i
  if s[i]=='(':
    i+=1
    res=expr(s)
    if s[i]==')':
      i+=1
    return res
  return number(s)
def number(s):
  global i
  res=''
  while i<len(s) and '0'<=s[i]<='9':
    res+=s[i]
    i+=1
  return int(res)
s=input()
i=0
print(expr(s))
            
            
            
        