結果
| 問題 |
No.708 (+ー)の式
|
| コンテスト | |
| ユーザー |
a01sa01to
|
| 提出日時 | 2025-10-19 00:52:22 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,020 bytes |
| コンパイル時間 | 4,502 ms |
| コンパイル使用メモリ | 278,440 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-10-19 00:52:28 |
| 合計ジャッジ時間 | 5,200 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;
class Parser {
private:
string s;
string::const_iterator itr;
public:
Parser(const string& t) {
s = t;
itr = s.begin();
}
int exec() {
int ans = 0;
{
bool pls = true;
while (itr != s.end()) {
if (*itr == ')') {
++itr;
return ans;
}
if (*itr == '(') {
++itr;
ans += exec() * (pls ? 1 : -1);
continue;
}
if (*itr == '+') {
++itr;
pls = true;
}
if (*itr == '-') {
++itr;
pls = false;
}
if (isdigit(*itr)) {
ans += (*itr - '0') * (pls ? 1 : -1);
++itr;
}
}
}
return ans;
}
};
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
string s;
cin >> s;
Parser parser(s);
cout << parser.exec() << '\n';
return 0;
}
a01sa01to