結果
問題 |
No.708 (+ー)の式
|
ユーザー |
👑 |
提出日時 | 2022-02-18 00:32:35 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,340 bytes |
コンパイル時間 | 793 ms |
コンパイル使用メモリ | 72,708 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-29 07:55:04 |
合計ジャッジ時間 | 1,449 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 RE * 2 |
ソースコード
#include <iostream> #include <stack> using namespace std; int main(){ string s;cin>>s; stack<int> x; for(int i = 0; s.size() > i; i++){ //cout << s[i] << s[i+1] << endl; if('0' <= s[i] && s[i] <= '9'){ x.push(s[i]-'0'); }else if(i+1 != s.size() && s[i+1] == '('){ stack<int> y; char l = s[i]; i+=2; while(s[i] != ')'){ if('0' <= s[i] && s[i] <= '9'){ y.push(s[i]-'0'); i++; }else if(s[i] == '+'){ int z = y.top();y.pop(); y.push(z+s[i+1]-'0'); i+=2; }else{ int z = y.top();y.pop(); y.push(z-(s[i+1]-'0')); i+=2; } } int b = x.top();x.pop(); if(l == '+'){ x.push(b+y.top()); }else{ x.push(b-y.top()); } }else{ int b = x.top();x.pop(); if(s[i] == '+'){ x.push(b+s[i+1]-'0'); i++; }else{ x.push(b-(s[i+1]-'0')); i++; } } //cout << x.top() << endl; } cout << x.top() << endl; }