File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+ using namespace std ;
3
+
4
+ typedef map<string, void *> node;
5
+
6
+ void printIndent (int depth){
7
+ for (;depth>0 ;--depth) cout<<" --" ;
8
+ }
9
+
10
+ void dfs (node root, int depth){
11
+ for (auto iter: root){
12
+ printIndent (depth);
13
+ cout<<iter.first <<" \n " ;
14
+ dfs (*(node*)iter.second , depth+1 );
15
+ }
16
+ }
17
+
18
+ int main () {
19
+ ios::sync_with_stdio (false ); cin.tie (NULL );
20
+
21
+ int N, K;
22
+
23
+ node root;
24
+ cin>>N;
25
+ for (int i=0 ;i<N;++i){
26
+ cin>>K;
27
+ node *cur = &root;
28
+
29
+ for (int j=0 ;j<K;++j){
30
+ string s;
31
+ cin>>s;
32
+ if (!(*cur)[s]) {(*cur)[s] = new node;}
33
+ cur = (node*)(*cur)[s];
34
+ }
35
+ }
36
+
37
+ for (auto iter: root){
38
+ cout<<iter.first <<" \n " ;
39
+ dfs (*(node*)iter.second , 1 );
40
+ }
41
+
42
+ return 0 ;
43
+ }
You can’t perform that action at this time.
0 commit comments