Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_MATH_DEFINES
- #include<stdio.h>
- #include<iostream>
- #include<vector>
- #include<cmath>
- #include<algorithm>
- #include<map>
- #include<set>
- #include<sstream>
- #include<cstring>
- #include<numeric>
- #include<limits.h>
- #include<time.h>
- using namespace std;
- struct item {
- string name;
- map<string, item> childs;
- item(){}
- item(string name): name(name) {}
- };
- map<string, item> roots;
- const int SZ = 100;
- char p[SZ];
- void add(item & cur, vector<string> & path, int stage) {
- if (stage >= path.size())
- return;
- else {
- if (cur.childs.count(path[stage]) == 0) {
- cur.childs[path[stage]] = item(path[stage]);
- }
- add(cur.childs[path[stage]], path, stage + 1);
- }
- }
- void add(vector<string> & path) {
- if (roots.count(*path.begin()) == 0) {
- roots[*path.begin()] = item(*path.begin());
- }
- add(roots[*path.begin()], path, 1);
- }
- void print(item cur, int fl) {
- for (int i = 0; i < fl; i++) {
- printf(" ");
- }
- printf("%s\n", cur.name.c_str());
- for (auto i : cur.childs) {
- print(i.second, fl + 1);
- }
- }
- int main() {
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- #endif
- int n;
- scanf("%d", &n);
- for (int i = 0; i < n; i++) {
- scanf("%s", p);
- vector<string> path;
- int len = strlen(p);
- int prev = 0;
- for (int j = 0; j < len; j++) {
- if (p[j] == '\\') {
- path.push_back(string(p + prev, p + j - 1));
- prev = j + 1;
- }
- }
- path.push_back(string(p + prev, p + len));
- add(path);
- }
- for (auto i : roots) {
- print(i.second, 0);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement