結果
| 問題 |
No.708 (+ー)の式
|
| コンテスト | |
| ユーザー |
Bantako
|
| 提出日時 | 2018-07-09 09:33:00 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,306 bytes |
| コンパイル時間 | 1,633 ms |
| コンパイル使用メモリ | 175,368 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-08 00:47:40 |
| 合計ジャッジ時間 | 2,323 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 WA * 3 |
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
8 | main(){
| ^~~~
ソースコード
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
string S;
cin >> S;
deque<char> cst;
deque<int> nst;
bool flag = 0;
int cnt = 0;
for(char c:S){
if(c == '(')flag = 1;
else if(c == ')'){
flag = 0;
rep(i,0,cnt){
int a = nst.back();
nst.pop_back();
int b = nst.back();
nst.pop_back();
if(cst.back() == '+'){
nst.push_back(b + a);
}else{
nst.push_back(b - a);
}
cst.pop_back();
}
cnt = 0;
}else if(c == '+' || c == '-'){
cst.push_back(c);
if(flag)cnt++;
}else{
nst.push_back(c - '0');
}
}
while(nst.size() > 1){
int a = nst.front();
nst.pop_front();
int b = nst.front();
nst.pop_front();
if(cst.front() == '+'){
nst.push_front(a + b);
}else{
nst.push_front(a - b);
}
cst.pop_front();
}
cout << nst.front() << endl;
}
Bantako