hiho week 169 register

Ended

Participants:408

Verdict:Accepted
Score:100 / 100
Submitted:2017-09-24 03:01:51

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<stack>
using namespace std;
int main()
{
    int number;
    char ch;
    stack<char> op;
    stack<int> operand;
    while(cin>>ch)
    {
        if(ch >= '0' && ch <= '9')
        {
            cin.unget();
            cin>>number;
            operand.push(number);
        }
        else
        {
            if(ch == '(' || op.empty()) op.push(ch);
            else if(ch == '*' || ch == '/')
            {
                while(!op.empty() && (op.top() == '*' || op.top() == '/'))
                {
                    int b = operand.top();operand.pop();
                    int a = operand.top();operand.pop();
                    char t = op.top();op.pop();
                    if(t == '*') a = a*b;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX