-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path727.cpp
More file actions
53 lines (52 loc) · 1.38 KB
/
727.cpp
File metadata and controls
53 lines (52 loc) · 1.38 KB
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
#include <bits/stdc++.h>
using namespace std;
#define mem(x, y) memset(x, y, sizeof(x));
stack<char> mid;
queue<char> ans;
int main() {
int i = 0, n;
char ch[10];
scanf("%d", &n);
getchar();
getchar();
while (n--) {
i++;
mid.push('(');
while (gets(ch) && strlen(ch)) {
if (ch[0] >= '0' && ch[0] <= '9') {
ans.push(ch[0]);
} else if (ch[0] == ')') {
while (mid.top() != '(') {
ans.push(mid.top());
mid.pop();
}
mid.pop();
} else if (ch[0] == '+' || ch[0] == '-') {
while (mid.top() != '(') {
ans.push(mid.top());
mid.pop();
}
mid.push(ch[0]);
} else if (ch[0] == '*' || ch[0] == '/') {
while (mid.top() == '/' || mid.top() == '*') {
ans.push(mid.top());
mid.pop();
}
mid.push(ch[0]);
} else
mid.push(ch[0]);
}
while (mid.top() != '(') {
ans.push(mid.top());
mid.pop();
}
mid.pop();
if (i != 1) puts("");
while (ans.size()) {
printf("%c", ans.front());
ans.pop();
}
puts("");
}
return 0;
}