-
Notifications
You must be signed in to change notification settings - Fork 2
/
00727.cpp
66 lines (62 loc) · 989 Bytes
/
00727.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
64
#include<iostream>
#include<stack>
#include<cctype>
#include<string>
#include<cstdio>
using namespace std;
int main()
{
int tn;
cin >> tn;
cin.ignore(100,'\n');
int i = 0;
while(tn--)
{
if(i++)
cout << endl;
cin.ignore(100,'\n');
string postfix, infix;
stack< char > s;
while(cin.peek() != '\n' && cin.peek() != EOF && cin.good())
{
char c = cin.get(); cin.ignore(100, '\n');
if(c == '(')
s.push(c);
else if(c == ')')
{
while(s.top() != '(')
{
cout << s.top();
s.pop();
}
s.pop();
}
else if(c == '+' || c == '-')
{
while(s.size() && s.top() != '(')
{
cout << s.top();
s.pop();
}
s.push(c);
}
else if(c == '*' || c == '/')
{
if(s.size() && (s.top() == '*' || s.top() == '/'))
{
cout << s.top();
s.pop();
}
s.push(c);
}
else
cout << c;
}
while(s.size())
{
cout << s.top();
s.pop();
}
cout << endl;
}
}