結果
問題 | No.708 (+ー)の式 |
ユーザー |
|
提出日時 | 2020-05-05 06:09:23 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 557 bytes |
コンパイル時間 | 2,182 ms |
コンパイル使用メモリ | 192,940 KB |
最終ジャッジ日時 | 2025-01-10 06:42:03 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
#include <bits/stdc++.h>#define rep(i,n) for(int i=0;i<(n);i++)using namespace std;int solve(string s){int n=s.length();int res=0;char op='+';rep(i,n){if(isdigit(s[i])){if(op=='+') res+=s[i]-'0';else res-=s[i]-'0';}else if(s[i]=='+' || s[i]=='-'){op=s[i];}else{ // '(' or ')'int j=i+1;while(s[j]!=')') j++;if(op=='+') res+=solve(s.substr(i+1,j-i-1));else res-=solve(s.substr(i+1,j-i-1));i=j;}}return res;}int main(){string s; cin>>s;cout<<solve(s)<<'\n';return 0;}