結果
| 問題 |
No.708 (+ー)の式
|
| コンテスト | |
| ユーザー |
🍮かんプリン
|
| 提出日時 | 2019-02-24 02:26:58 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 945 bytes |
| コンパイル時間 | 1,671 ms |
| コンパイル使用メモリ | 161,672 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-12-16 01:54:01 |
| 合計ジャッジ時間 | 2,169 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 4 WA * 8 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
int cal(string s) {
int a;
if (s[0]!='(') {
a=(int)s[0]-'0';
if (s.length()>1) {
switch(s[1]) {
case '+':
a+=cal(s.substr(2));
break;
case '-':
a-=cal(s.substr(2));
break;
}
}
}
else {
size_t i=0;
while(s[i]!=')') {
i++;
}
a=cal(s.substr(1,i-1));
if (s.length()>i+1) {
switch(s[i+1]) {
case '+':
a+=cal(s.substr(i+2));
break;
case '-':
a-=cal(s.substr(i+2));
break;
}
}
}
return a;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s;
cin >> s;
cout << cal(s) << endl;
return 0;
}
🍮かんプリン