# hihoCoder 1551-合并子目录

hihoCoder 1551-合并子目录

### 描述

/hihocoder/offer22/solutions/p1
/hihocoder/challenge30/p1/test
/game/moba/dota2/uninstall

/hihocoder
/hihocoder/offer22
/hihocoder/offer22/solutions
/hihocoder/challenge30
/hihocoder/challenge30/p1
/game
/game/moba
/game/moba/dota2/

### 输出

```3
/hihocoder/offer22/solutions/p1
/hihocoder/challenge30/p1/test
/game/moba/dota2/uninstall```

`8`

```#include<algorithm>
#include<vector>
#include<iostream>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<set>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
struct Node {
string key_;
map<string, Node*> children_;
Node(string key) :key_(key) {};
};
int main() {
//freopen("input.txt", "r", stdin);
int n;
scanf("%d\n", &n);
string line;
Node* root = new Node("");
while (n--) {
getline(cin, line);
int pre = 0;
int pos = line.find('//');
Node* cur = root;
while (pos != string::npos) {
if (pos != 0) {
string tmp = line.substr(pre + 1, pos - pre - 1);
if (cur->children_[tmp] == NULL) {
cur->children_[tmp] = new Node(tmp);
}
cur = cur->children_[tmp];
}
pre = pos;
pos = line.find('//', pos + 1);
}
}
ll ans = 0;
queue<Node*> q;
q.push(root);
while (!q.empty()) {
Node* cur = q.front();
q.pop();
++ans;
for (auto it : cur->children_) {
q.push(it.second);
}
}
printf("%lld\n", ans - 1);
return 0;
}
```

This site uses Akismet to reduce spam. Learn how your comment data is processed.