結果
| 問題 |
No.708 (+ー)の式
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-10-12 04:03:18 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 569 bytes |
| コンパイル時間 | 1,888 ms |
| コンパイル使用メモリ | 194,500 KB |
| 最終ジャッジ日時 | 2025-01-15 06:49:23 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int i=0;
int cal(string s){
int res=0;
int sgn=1;
for(;i<s.size();i++){
if(s[i]==')')break;
sgn=1;
if(s[i]=='-')sgn=-1;
if(s[i]=='+' or s[i]=='-')i++;
res+=sgn*(s[i]-'0');
}
return res;
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
string s; cin >> s;
int n=s.size();
int res=0;
s="+"+s;
for(;i<n;i++){
int sgn=1;
if(s[i]=='-')sgn=-1;
i++;
if(s[i]=='('){
i++;
res+=sgn*cal(s);
}
else{
res+=sgn*(s[i]-'0');
}
}
cout << res << endl;
}