-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1991.cpp
More file actions
53 lines (47 loc) · 780 Bytes
/
1991.cpp
File metadata and controls
53 lines (47 loc) · 780 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
47
48
49
50
51
52
53
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#define io ios::sync_with_stdio(false); cin.tie(0);
using namespace std;
int N;
map<char,pair<char,char>> tree;
void pre(char p){
if(p!='.'){
cout<<p;
pre(tree[p].first);
pre(tree[p].second);
}
}
void in(char p){
if(p!='.'){
in(tree[p].first);
cout<<p;
in(tree[p].second);
}
}
void post(char p){
if(p!='.')
{
post(tree[p].first);
post(tree[p].second);
cout<<p;
}
}
int main()
{
io;
cin>>N;
for(int i=0;i<N;i++){
char p,l,r;
cin>>p>>l>>r;
tree[p]={l,r};
}
pre('A');
cout<<'\n';
in('A');
cout<<'\n';
post('A');
cout<<'\n';
return 0;
}