#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <algorithm>
using namespace std;
void func()
{
int n;
string str;
vector<string> v;
while(cin>>n){
if(n==0)break;
v.resize(0);
while(n--){
cin>>str;
if(str[str.length()-1]=='\\'){
str.erase(str.length()-1,str.length());
}
if(find(v.begin(),v.end(),str)==v.end()){
v.push_back(str);
}
while(str.find('\\')!=string::npos){
str.erase(str.find_last_of('\\'),str.length());
if(find(v.begin(),v.end(),str)==v.end()){
v.push_back(str);
}
}
}
sort(v.begin(),v.end());
for(int i=0;i<v.size();i++){
if(v[i].find('\\')==string::npos){
cout<<v[i]<<endl;
}
else{
for(int j=0;j<v[i].find_last_of('\\');j++){
cout<<" ";
}
cout<<" ";
cout<<v[i].substr(v[i].find_last_of('\\')+1,v[i].length());
cout<<endl;
}
}
cout<<endl;
}
}
int main(int argc, char *argv[])
{
//printf("Hello, world\n");
func();
return 0;
}
将每个子路径保存,然后排序,再按格式输出
-
题目描述:
-
给你一串路径,譬如:
a\b\c
a\d\e
b\cst
d\
你把这些路径中蕴含的目录结构给画出来,子目录直接列在父目录下面,并比父目录向右缩一格,就像这样:
a
b
c
d
e
b
cst
d
同一级的需要按字母顺序排列,不能乱。
-
输入:
-
每个测试案例第一行为一个正整数n(n<=10)表示有n个路径,当n为0时,测试结束,接下来有n行,每行有一个字串表示一个路径,长度小于50。
-
输出:
-
输出目录结构,每一个测试样例的输出紧跟一个空行。
-
样例输入:
-
4 a\b\c a\d\e b\cst d\ 0
-
样例输出:
-
a b c d e b cst d