| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
这就是STL吗?#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
struct Directory{
string name;
vector<Directory*> subdirect;
vector<string> file;
};
void SubInput( Directory* p){
string input;
Directory* tem;
while (cin >> input, input[0] != ']'){
if (input[0] == 'f') (p->file).push_back(input);
else{
tem = new Directory;
tem->name = input;
(p->subdirect).push_back(tem);
SubInput(tem);
}
}
return;
}
void SubOutput ( Directory* p, int ceng){
for (vector<Directory*>::iterator i = (p->subdirect).begin(); i != (p->subdirect).end(); ++i){
for (int j = 1; j <= ceng; ++j) cout<< "| ";
cout << (*i)->name << endl;
SubOutput (*i, ceng+1);
}
sort (p->file.begin(), p->file.end());
for (vector<string>::iterator i = p->file.begin(); i != p->file.end(); ++i){
for (int j = 1; j < ceng; ++j) cout<< "| ";
cout<< *i << endl;
}
}
int main()
{
Directory* root = new Directory;
Directory* tem;
string input;
int count = 0, ceng = 0;
while (cin >> input, input[0] != '#'){
++count;
if (input[0] == '*'){
if (count != 1) cout <<endl;
cout<<"DATA SET "<<count<<":"<<endl<<"ROOT"<<endl;
}
if (input[0] != '*'){
root->file.clear();
root->subdirect.clear();
while (input[0] != '*'){
if (input[0] == 'f') (root->file).push_back(input);
else{
tem = new Directory;
tem->name = input;
(root->subdirect).push_back(tem);
SubInput(tem);
}
cin >> input;
}
if (count != 1) cout <<endl;
cout<<"DATA SET "<<count<<":"<<endl<<"ROOT"<<endl;
ceng = 1;
for (vector<Directory*>::iterator i = (root->subdirect).begin(); i != (root->subdirect).end(); ++i){
cout << "| " << (*i)->name << endl;
SubOutput (*i, ceng+1);
}
sort (root->file.begin(), root->file.end());
for (vector<string>::iterator i = root->file.begin(); i != root->file.end(); ++i) cout<< *i << endl;
}
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator