結果
問題 |
No.708 (+ー)の式
|
ユーザー |
![]() |
提出日時 | 2018-11-27 16:07:40 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,086 bytes |
コンパイル時間 | 667 ms |
コンパイル使用メモリ | 62,200 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-23 18:09:14 |
合計ジャッジ時間 | 1,455 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 4 WA * 8 |
ソースコード
#include <iostream> #include <stack> int main() { char s[101]; std::cin >> s; std::stack<char> stk; for(int i = 0; s[i]; i++) { if((s[i] > '0') && (s[i] < '9')) s[i] -= '0'; stk.push(s[i]); } int ans = 0; int temp = 0; int sign = 0; char pop; while(!stk.empty()) { pop = stk.top(); stk.pop(); if(pop <= 9) { switch(sign) { case 0: ans = pop; break; case 1: ans += pop; break; case -1: ans = pop - ans; } sign = 0; } if(pop == '+') sign = 1; if(pop == '-') sign = -1; if(pop == ')') { temp = ans * sign; sign = 0; } if(pop == '(') { stk.push(ans); stk.push('+'); stk.push(temp); sign = 0; ans = 0; } } std::cout << ans << std::endl; return 0; }