-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1233.cpp
More file actions
48 lines (37 loc) · 994 Bytes
/
1233.cpp
File metadata and controls
48 lines (37 loc) · 994 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
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
std::vector<std::string> removeSubfolders(std::vector<std::string>& folder) {
std::vector<std::string> result;
std::sort(folder.begin(), folder.end());
for (const std::string& current : folder) {
if (result.empty() ||
!(current.size() > result.back().size() &&
current.compare(0, result.back().size(), result.back()) == 0 &&
current[result.back().size()] == '/')) {
result.push_back(current);
}
}
return result;
}
int main() {
std::vector<std::string> folder = {
"/a",
"/a/b",
"/c/d",
"/c/d/e",
"/c/f",
// "/a",
// "/a/b/c",
// "/a/b/d",
// "/a/b/c",
// "/a/b/ca",
// "/a/b/d",
};
std::vector<std::string> fd = removeSubfolders(folder);
for(const auto& i : fd) {
std::cout << i << " ";
}
std::cin.get();
}