Disk Tree
来源:互联网 发布:如何下载别人淘宝视频 编辑:程序博客网 时间:2024/05/17 08:29
3:Disk Tree
- 查看
- 提交
- 统计
- 提问
- 总时间限制:
- 1000ms
- 内存限制:
- 65536kB
- 描述
- Hacker Bill has accidentally lost all the information from his workstation's hard drive and he has no backup copies of its contents. He does not regret for the loss of the files themselves, but for the very nice and convenient directory structure that he had created and cherished during years of work. Fortunately, Bill has several copies of directory listings from his hard drive. Using those listings he was able to recover full paths (like "WINNT\SYSTEM32\CERTSRV\CERTCO~1\X86") for some directories. He put all of them in a file by writing each path he has found on a separate line. Your task is to write a program that will help Bill to restore his state of the art directory structure by providing nicely formatted directory tree.
- 输入
- The first line of the input file contains single integer number N (1 <= N <= 500) that denotes a total number of distinct directory paths. Then N lines with directory paths follow. Each directory path occupies a single line and does not contain any spaces, including leading or trailing ones. No path exceeds 80 characters. Each path is listed once and consists of a number of directory names separated by a back slash ("\").
Each directory name consists of 1 to 8 uppercase letters, numbers, or the special characters from the following list: exclamation mark, number sign, dollar sign, percent sign, ampersand, apostrophe, opening and closing parenthesis, hyphen sign, commercial at, circumflex accent, underscore, grave accent, opening and closing curly bracket, and tilde ("!#$%&'()-@^_`{}~"). - 输出
- Write to the output file the formatted directory tree. Each directory name shall be listed on its own line preceded by a number of spaces that indicate its depth in the directory hierarchy. The subdirectories shall be listed in lexicographic order immediately after their parent directories preceded by one more space than their parent directory. Top level directories shall have no spaces printed before their names and shall be listed in lexicographic order. See sample below for clarification of the output format.
- 样例输入
7WINNT\SYSTEM32\CONFIGGAMESWINNT\DRIVERSHOMEWIN\SOFTGAMES\DRIVERSWINNT\SYSTEM32\CERTSRV\CERTCO~1\X86
- 样例输出
GAMES DRIVERSHOMEWIN SOFTWINNT DRIVERS SYSTEM32 CERTSRV CERTCO~1 X86 CONFIG
- 来源
- Northeastern Europe 2000
#include<iostream>#include<cmath>#include<cstring>#include<algorithm>#include<iomanip>#include<queue>#include<stack>#include<vector>#include<set>#include<map>using namespace std;map<string,int>M[20005];char c[85];int Dic[45];int TotalDicnum=0;void Pre(int dic,int offset){for(map<string,int>::iterator it=M[dic].begin();it!=M[dic].end();++it){for(int i=0;i<offset;++i)cout<<" ";cout<<(it->first).c_str()<<endl;Pre(it->second,offset+1);}}int main(){int n;cin>>n;while(n--){scanf("%s",c);Dic[0]=0;int Dicnum=1;int len=strlen(c);for(int i=0;i<len;++i){if(c[i]=='\\'){c[i]=0;Dic[Dicnum++]=i+1;}}int dic=0;for(int i=0;i<Dicnum;++i){string s=c+Dic[i];if(!M[dic].count(s)){M[dic][s]=(++TotalDicnum);}dic=M[dic][s];}}Pre(0,0);return 0;}
阅读全文
0 0
- Disk Tree
- Disk Tree
- HDU 1504 Disk Tree
- poj1760 Disk Tree
- poj-1760 Disk Tree
- UVa 1556 - Disk Tree
- POJ 1760 Disk Tree 笔记
- UVA 1556 - Disk Tree(Trie)
- uva 1556 - Disk Tree(字典树)
- timus 1067 Disk Tree【超时代码】
- disk
- URAL 1067. Disk Tree (STL vector 使用)
- Disk&Memory
- IPHONE Disk
- Disk info
- disk dump
- disk utility
- disk recovery
- 解决sqoop中出现的某些问题
- 寻找“coder”,从字符串数组中寻找特定字符串
- jpeg链接错误 iOS
- 【记录】RabbitMq、ActiveMq、ZeroMq、kafka之间的比较
- Python中单下划线,双下划线,俩头下划线的区别。
- Disk Tree
- CoreJava——阶段测试题(一)
- 面试的一个简单题
- Jsoup实现简单的爬虫
- hdu-6180-Schedule
- hdu 6178 Monkeys
- 小黑屋反馈总结
- C++中的类型转换
- 点到三维网格最近点距离