-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathONP.cpp
More file actions
46 lines (40 loc) · 644 Bytes
/
Copy pathONP.cpp
File metadata and controls
46 lines (40 loc) · 644 Bytes
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
#include <iostream>
#include <string>
using namespace std;
int temp;
struct tree{
char val;
tree* right;
tree* left;
int start,end;
tree(string str,int s){
if(str[s]=='('){
left = new tree(str,s+1);
val = str[temp];
right = new tree(str,temp+1);
temp = temp+1;
} else {
val = str[s];
left = NULL;
right = NULL;
temp = s+1;
}
}
string RPN(){
if(right==NULL&&left==NULL)
return string(1,val);
else
return left->RPN()+right->RPN()+val;
}
};
int main(){
int T;
cin >> T;
string str;
for (int t = 0; t < T; ++t)
{
cin >> str;
cout << tree(str,0).RPN() << endl;
}
return 0;
}