-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1067.cpp
72 lines (61 loc) · 1.61 KB
/
1067.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
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <map>
/**
* все до безобразия просто -- строим дерево
*/
struct tree {
tree() {
this->name = "";
this->child = {};
}
tree(std::string name) {
this->name = name;
this->child = {};
}
tree(std::string name, std::map< std::string, tree *> child) {
this->name = name;
this->child = child;
}
std::string name;
std::map< std::string, tree *> child;
};
void print_tr(tree *tr, int n) {
for (int i = 0; i < n - 1; ++i) {
std::cout << " ";
}
if (tr->name != "") {
std::cout << tr->name << std::endl;
}
++n;
for (auto &j : tr->child) {
print_tr(j.second, n);
}
}
int main() {
int n;
std::cin >> n;
tree *tr_root = new tree();
for (int i = 0; i < n; ++i) {
std::string patch;
std::cin >> patch;
std::string dir = "";
tree *tr = tr_root;
for (int j = 0; j <= patch.size(); ++j) {
if (patch[j] == '\\' || patch[j] == '\0') {
auto dir_tr = tr->child.find(dir);
if (dir_tr == tr->child.end()){
tree *new_tree = new tree(dir);
tr->child[dir] = new_tree;
tr = tr->child.find(dir)->second;
} else {
tr = dir_tr->second;
}
dir = "";
} else {
dir += patch[j];
}
}
}
print_tr(tr_root, 0);
return 0;
}