-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathONP-4617403-src.cpp
63 lines (57 loc) · 1.29 KB
/
ONP-4617403-src.cpp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include<stdio.h>
#include<stack>
#include<stdlib.h>
#include<string>
#include <iostream>
using namespace std;
int main()
{
//int flag = 0;
string exp;
string n1;
string ch;
int t;
cin >> t;
int i;
while(t--)
{
i = 0;
n1 = "";
stack<string> stck;
cin >> exp;
//cout << exp <<endl; /**/
while (i<exp.length())
{
//cout << i <<endl;
ch = exp.at(i);
//cout << ch <<endl;
if(ch[0] == '(')
{
//cout <<"success" <<endl;
//flag++;
}
else if(ch[0] == '+'||ch[0] == '-'||ch[0] == '*'||ch[0] == '/'||ch[0] == '^')
{
//cout <<"pushed" <<endl;
stck.push(ch);
}
else if(ch[0] == ')')
{
//cout <<"poped" <<endl;
if(stck.empty() == 0)
{
n1.append(stck.top());
stck.pop();
}
}
else
{
//cout <<"appended" <<endl;
n1.append(ch);
}
i++;
}
cout << n1 <<endl;
}
return 0;
}