結果
| 問題 |
No.708 (+ー)の式
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-11-23 22:02:42 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,160 bytes |
| コンパイル時間 | 454 ms |
| コンパイル使用メモリ | 55,480 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-24 18:55:55 |
| 合計ジャッジ時間 | 1,453 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
ソースコード
#include<iostream>
#include<string>
using namespace std;
int main() {
const char p = '+';
const char m = '-';
const char bl = '(';
const char br = ')';
bool pos = true;
bool bracket = false;
bool tmp_pos = true;
string s;
cin >> s;
long res = 0;
for (int i = 0; i < s.size(); i++){
if (s[i] == p){
pos = true;
continue;
}
if (s[i] == m){
pos = false;
continue;
}
if (s[i] == bl){
tmp_pos = pos;
i++;
while (s[i] != br){
if (s[i] == p) tmp_pos = pos;
else if (s[i] == m) tmp_pos = !pos;
else {
if (tmp_pos == true) res += static_cast<int>(s[i] - '0');
else res -= static_cast<int>(s[i] - '0');
}
i++;
}
}
if (s[i] == br){
bracket = false;
continue;
}
if (pos == true) res += static_cast<int>(s[i] - '0');
else res -= static_cast<int>(s[i] - '0');
}
cout << res << "\n";
}