結果
| 問題 |
No.708 (+ー)の式
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-06-30 10:19:06 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 687 bytes |
| コンパイル時間 | 1,498 ms |
| コンパイル使用メモリ | 166,576 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-01 00:51:00 |
| 合計ジャッジ時間 | 2,121 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
ソースコード
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;
int st = 0;
std::string s;
int func() {
int ret = 0;
if('0' <= s[st] and s[st] <= '9') {
ret = s[st] - '0';
st++;
} else if(s[st] == '(') {
st += 1;
ret += func();
}
for(; st < s.size(); st += 2) {
if(s[st] == '+') {
if(s[st + 1] == '(') {
st += 2;
ret += func();
} else {
ret += s[st + 1] - '0';
}
} else if(s[st] == '-') {
if(s[st + 1] == '(') {
st += 2;
ret -= func();
} else {
ret -= s[st + 1] - '0';
}
}
if(s[st] == ')'){
st--;
return ret;
}
}
return ret;
}
int main(){
cin >> s;
cout << func() << endl;
return 0;
}