博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Disk Tree
阅读量:6672 次
发布时间:2019-06-25

本文共 3004 字,大约阅读时间需要 10 分钟。

题目描述

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.

样例输入

7

WINNT\SYSTEM32\CONFIG
GAMES
WINNT\DRIVERS
HOME
WIN\SOFT
GAMES\DRIVERS
WINNT\SYSTEM32\CERTSRV\CERTCO~1\X86

样例输出

GAMES DRIVERSHOMEWIN SOFTWINNT DRIVERS SYSTEM32  CERTSRV   CERTCO~1    X86  CONFIG

瞎搞代码,只能在学校OJ上交过,POJ上交超时

一开始想成文件名不重复了,正解是手动链树,多叉转二叉,添加节点的时候排序,vector瞎搞模拟有点慢,懒得改了

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;int n,cnt,T;struct E{ string s; int pla; vector
v;};E fir[520];E node[20020];int fircnt=0;int cmp(E x,E y){ return x.s
>T; T=1; while(T--){ //for(int i=1;i<=cnt;i++) a[i].clear(); cnt=fircnt=0; //memset(e,0,sizeof(e)); //memset(root,0,sizeof(root)); //mp.clear(); cin>>n; string s0; for(int i=1;i<=n;i++){ cin>>s0; int x1=-1,x2=-1; string tmps="";//,last=""; int last=0,tmp,cur=0; for(int j=0;j

转载于:https://www.cnblogs.com/sz-wcc/p/11071961.html

你可能感兴趣的文章
PHP实时统计文件下载次数
查看>>
linux eth0 改eth1 在改ip
查看>>
乾颐堂鹏同学通过HCIE送给后来者的话
查看>>
JS中的prototype
查看>>
我的友情链接
查看>>
本体编辑和知识获取软件--protege汉化版
查看>>
23张非常精美的圣诞桌面壁纸分享
查看>>
稀疏矩阵的压缩存储和转置
查看>>
华为S5700交换机开启WEB配置
查看>>
mysql主从同步错误解决和Slave_IO_Running: NO
查看>>
Coding and Paper Letter(十七)
查看>>
性能下降曲线
查看>>
求一个数的二进制中1的个数
查看>>
古代教育观点纵览
查看>>
Linux 下搭建PHP环境(make方法)太麻烦了
查看>>
《三》kubectl命令行管理工具、YAML配置详解
查看>>
iozone测试文件系统性能
查看>>
Hadoop - HDFS的数据流剖析
查看>>
Win7下部署asp.net程序如果有RDLC报表需要以下配置
查看>>
Jhipster_cn中文翻译组
查看>>