#include<iostream>
#include<cstring>
#include<string>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;
struct node {
node() {};
node(string name): name(name) {};
string name;
vector<node*> dir;
vector<string> file;
} *nds[100000];
node *root;
bool cmp(string s1, string s2) {
return s1 < s2;
}
void pre(node *nd, string str) {
cout << str << nd->name << endl;
int len, i;
if (nd->dir.size() != 0) {
len = nd->dir.size();
for (i = 0; i < len; i++) {
pre(nd->dir[i], str + "| ");
}
}
if (nd->file.size() != 0) {
len = nd->file.size();
vector<string> v = nd->file;
sort(v.begin(), v.end(), cmp);
for (i = 0; i < len; i++) {
cout << str << v[i] << endl;
}
}
}
int main() {
string name;
int t, coun;
coun = 0;
while (cin >> name && name[0] != '#') {
if (coun)printf("\n");
root = new node("ROOT");
t = 0;
nds[t] = root;
if (name[0] == 'd') {
t++;
nds[t] = new node(name);
nds[t - 1]->dir.push_back(nds[t]);
} else if (name[0] == 'f') {
nds[t]->file.push_back(name);
}
while (cin >> name && name[0] != '*') {
if (name[0] == 'd') {
t++;
nds[t] = new node(name);
nds[t - 1]->dir.push_back(nds[t]);
} else if (name[0] == 'f') {
nds[t]->file.push_back(name);
} else if (name[0] == ']') {
t--;
}
}
printf("DATA SET %d:\n", ++coun);
pre(root, "");
}
}
zoj 1809 File Mapping
最新推荐文章于 2024-08-21 18:53:45 发布