題目鏈接

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <list>
#include <iomanip>
#include <bitset>
//#include <sstream>
//#include <regex>
//#include <functional>
using namespace std;
struct Node {
string data;
set<Node*>link;
set<string>file;
bool operator<(const Node& n)const {
return data < n.data;
}
};
bool cmp(Node* a, Node* b) {
return a->data < b->data;
}
void insert(Node* root, string str) {
if (str.empty())
return;
Node* n = new Node();
int index = str.find('\\');
cout << " find_index:" << index << endl;
if (index != -1) {
string s = str.substr(0, index);
n->data = s;
for (auto& it : root->link)
if (it->data == n->data) {
n = it;
break;
}
root->link.insert(n);
str = str.substr(index + 1);
insert(n, str);
}
else {
root->file.insert(str);
}
return;
}
void print(Node root, int n) {
for (int i = 0; i < n; ++i)
cout << " ";
cout << root.data << endl;
for (auto& it : root.link)
print(*it, n + 1);
for (auto& it : root.file) {
for (int i = 0; i < n + 1; ++i)
cout << " ";
cout << it << endl;
}
}
int main() {
int N;
string str;
Node root, n;
root.data = "root";
cin >> N;
while (N--) {
cin >> str;
insert(&root, str);
}
print(root, 0);
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/168208.html
標籤:C++ 語言
上一篇:Python3標準庫:io文本、十進制和原始流I/O工具
下一篇:python oct函式
