-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14725_Trie.cpp
More file actions
53 lines (44 loc) · 799 Bytes
/
14725_Trie.cpp
File metadata and controls
53 lines (44 loc) · 799 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 <cstring>
#include <map>
using namespace std;
int n, k;
class Node
{
private:
public:
string str;
map<string, Node> child;
void set_child(int num)
{
if (num == 0) return;
string s;
cin >> s;
child[s].set_child(num - 1);
}
void get_child(int num)
{
for (auto temp : child)
{
for (int i = 0; i < num; i++)
cout << "--";
cout << temp.first << '\n';
temp.second.get_child(num + 1);
}
}
};
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
Node root;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> k;
root.set_child(k);
}
root.get_child(0);
return 0;
}