-
Notifications
You must be signed in to change notification settings - Fork 0
/
00727.cpp
66 lines (56 loc) · 1.23 KB
/
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
65
66
#include <bits/stdc++.h>
using namespace std;
#define ll long long
map<string, ll> prio({
{"+", 0},
{"-", 0},
{"*", 1},
{"/", 1},
});
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
string temp;
ll t; cin >> t;
cin.ignore(1000, '\n');
getline(cin, temp);
stack<string> q;
ll sp = 0;
while(getline(cin, temp)){
if(temp.empty()){
while(!q.empty()){
cout << q.top();
q.pop();
}
cout << "\n\n";
}
if(isdigit(temp[0])){
cout << temp;
}
else if(temp == "("){
q.push(temp);
}
else if(temp == ")"){
while(q.top() != "("){
cout << q.top();
q.pop();
}
q.pop();
}
else{
while(!q.empty() && q.top() != "(" && prio[q.top()] >= prio[temp]){
cout << q.top();
q.pop();
}
q.push(temp);
}
}
while(!q.empty()){
cout << q.top();
q.pop();
}
cout << "\n";
return 0;
}