hiho week 169 register

Ended

Participants:408

Verdict:Accepted
Score:100 / 100
Submitted:2017-09-25 14:36:13

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<iostream>
#include<string>
#include<stack>
using namespace std;
int main(){
    string s;
    cin>>s;
    stack<char> op;
    stack<int> num;
    int i=0,res=0;
    for(i=0;i<=s.size();){
        if(i==s.size()||s[i]==')'){
            res=num.top();
            num.pop();
            while(!num.empty()&&!op.empty()&&op.top()!='('){
                if(op.top()=='+')   res+=num.top();
                //else if(op.top()=='-')   res=num.top()-res;
                //else if(op.top()=='*') res*=num.top();
                //else res=num.top()/res;
                num.pop();
                op.pop();
            }
            if(!op.empty())
                op.pop();
            while(!op.empty()&&(op.top()=='*'||op.top()=='/')){
                int a=num.top();
                num.pop();
                if(op.top()=='*')res=a*res;
                else res=a/res;
                op.pop();
            }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX