結果
| 問題 |
No.708 (+ー)の式
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-11-18 02:34:01 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 651 bytes |
| コンパイル時間 | 578 ms |
| コンパイル使用メモリ | 62,932 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-11-18 02:34:03 |
| 合計ジャッジ時間 | 1,608 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
ソースコード
#include <iostream>
using namespace std;
string s;
bool in;
int x, y, ans;
int main() {
cin >> s;
ans = 0, x = y = 1;
in = false;
for (int i = 0; i < s.size(); ++i) {
if ('0' <= s[i] && s[i] <= '9') {
ans += x * y * (s[i] - '0');
} else if (s[i] == '+') {
if (in) y = 1;
else x = 1, y = 1;
} else if (s[i] == '-') {
if (in) y = -1;
else x = -1, y = 1;
} else if (s[i] == '(') {
in = true;
} else if (s[i] == ')') {
in = false;
x = y = 1;
}
}
printf("%d\n", ans);
return 0;
}