-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisk Tree.cpp
61 lines (51 loc) · 931 Bytes
/
Disk Tree.cpp
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
#include <bits/stdc++.h>
using namespace std;
int n,sz;
char str[85];
struct Node{
string name;
map<string,int> vis;
}node[50005];
void insert(char *str){
int len=strlen(str);
str[len]='\\';
int u=0;
for(int i=0;i<=len;i++){
string tmp="";
while(str[i] != '\\'){
tmp += str[i];
i++;
}
if(!node[u].vis.count(tmp)){
node[sz].vis.clear();
node[sz].name = tmp;
node[u].vis[tmp] = sz++;
}
u=node[u].vis[tmp];
}
}
void init(){
sz=1;
node[0].vis.clear();
while(n--){
cin>>str;
insert(str);
}
}
void print(int u,int d){
if(u){
for(int i=0;i<d;i++) cout << " ";
cout << node[u].name << endl;
}
for(map<string,int>::iterator it=node[u].vis.begin();it!=node[u].vis.end();it++){
print(it->second,d+1);
}
}
int main(int argc, char** argv) {
while(cin>>n){
init();
print(0,-1);
//cout << endl;
}
return 0;
}