先上题目:
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

该博客讲述了如何利用STL Map的数据结构,根据给定的目录路径列表,重建并按字典序输出目录树结构。通过创建一个森林,然后对森林中的每棵树进行先根遍历,同时利用Map在插入时保持key有序的特性,来实现按字典序的目录树输出。
最低0.47元/天 解锁文章
1750

被折叠的 条评论
为什么被折叠?



