結果
| 問題 |
No.708 (+ー)の式
|
| コンテスト | |
| ユーザー |
kyawashell
|
| 提出日時 | 2018-06-29 22:52:10 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 688 bytes |
| コンパイル時間 | 650 ms |
| コンパイル使用メモリ | 68,888 KB |
| 最終ジャッジ日時 | 2025-01-06 11:42:58 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
ソースコード
#include<iostream>
#include<string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
string s;
bool isN(char c) {
return c >= '0' && c <= '9';
}
ll calc(string s) {
ll ret = 0;
bool f = true;
rep(i,s.size()) {
if(isN(s[i])) {
if(f)ret+=s[i]-'0';
else ret-=s[i]-'0';
}else if(s[i] == '+')f = true;
else if(s[i] == '-')f = false;
else {
ll j = i;
while(s[i]!=')')i++;
ll d =calc(s.substr(j+1,i-j-1));
if(f)ret+=d;
else ret-=d;
}
}
return ret;
}
int main() {
cin >> s;
cout << calc(s) << endl;
}
kyawashell