-
Notifications
You must be signed in to change notification settings - Fork 0
/
1991
72 lines (47 loc) · 921 Bytes
/
1991
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
67
68
69
70
71
72
#include <iostream>
#include <vector>
using namespace std;
// 0 : 해당자리가 비어있음을 의미
int lc[26];
int rc[26];
void preorder(int cur){
if(cur == -1) return;
cout << char(cur+'A');
preorder(lc[cur]);
preorder(rc[cur]);
}
void inorder(int cur){
if(cur == -1) return;
inorder(lc[cur]);
cout << char(cur+'A');
inorder(rc[cur]);
}
void postorder(int cur){
if(cur == -1) return;
postorder(lc[cur]);
postorder(rc[cur]);
cout << char(cur+'A');
}
int main() {
fill(lc, lc+26, -1);
fill(rc, rc+26, -1);
int N;
cin>>N;
for(int i=0; i<N; i++){
char c, l, r;
cin>>c>>l>>r;
if(l != '.') lc[c-'A'] = l-'A';
if(r != '.') rc[c-'A'] = r-'A';
}
for(int i=0; i< 26; i++)
cout<<lc[i]<<" ";
preorder(0); cout<<'\n';
inorder(0); cout<<'\n';
postorder(0);
}
/*
ASCII코드표
A : 65
B : 66
...
*/