Disk Tree

Time limit: 2.0 second
Memory limit: 64 MB
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.

Input

The first line of the input 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 ("!#$%&'()-@^_`{}~").

Output

Write to the output 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.

Sample

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

分析:trie树;

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=4e4+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,k,t,id;
set<pair<string,int> >::iterator ptr;
struct node
{
set<pair<string,int> >p;
}a[maxn];
char b[maxn],c[maxn];
void dfs(int now,int t)
{
for(set<pair<string,int> >::iterator it=a[now].p.begin();it!=a[now].p.end();it++)
{
for(int i=;i<t;i++)printf(" ");
printf("%s\n",it->fi.c_str());
dfs(it->se,t+);
}
}
int main()
{
int i,j;
scanf("%d",&n);
rep(t,,n)
{
scanf("%s",b);
int len=strlen(b);
b[len]='\\';
b[len+]=;
j=;
int now=;
for(i=;b[i];i++)
{
if(b[i]!='\\')c[j++]=b[i];
else
{
c[j]=;
ptr=a[now].p.lower_bound(mp(c,));
if(ptr==a[now].p.end()||strcmp(ptr->fi.c_str(),c)!=)
{
a[now].p.insert(mp(c,++id));
now=id;
}
else now=ptr->se;
j=;
}
}
}
dfs(,);
//system("Pause");
return ;
}

ural1067 Disk Tree的更多相关文章

  1. uva 1556 - Disk Tree(特里)

    题目连接:uva 1556 - Disk Tree 题目大意:给出N个文件夹关系,然后依照字典序输出整个文件文件夹. 解题思路:以每一个文件夹名作为字符建立一个字典树就可以,每一个节点的关系能够用ma ...

  2. HDU 1504 Disk Tree

    转载请注明出处:http://blog.csdn.net/a1dark 分析:查了一下这题.发现网上没有什么关于这道题的解题报告.其实题目意思挺好懂的.就是给你一些文件的目录结构.然后让你把它们组合在 ...

  3. 1067. Disk Tree(字符串)

    1067 破题啊  写完发现理解错题意了 子目录下会有跟之前重名的 把输入的字符串存下来 排下序 然后依次找跟上面有没有重的 #include <iostream> #include< ...

  4. 【HDOJ】1504 Disk Tree

    文件可以重名.先按字典序将路径排序,再过滤掉公共前缀.其中的问题是'\'的ASCII比[A-Z0-9]大,将它替换为空格.否则字典序有问题. /* 1504 */ #include <iostr ...

  5. Linux平台下源码安装mysql多实例数据库

    Linux平台下源码安装mysql多实例数据库[root@linux-node1 ~]# netstat -tlunp | grep 330tcp6 0 0 :::3306 :::* LISTEN 6 ...

  6. 04.ubuntu下kvm 命令行安装64位ubuntu报"Couldn't find hvm kernel for Ubuntu tree."的问题

    1.安装ubuntu时使用的virt-install的配置: virt-install \ --name test4 \ --ram 1024 \ --disk path=/data/01_ubunt ...

  7. SSIS Data Flow 的 Execution Tree 和 Data Pipeline

    一,Execution Tree 执行树是数据流组件(转换和适配器)基于同步关系所建立的逻辑分组,每一个分组都是一个执行树的开始和结束,也可以将执行树理解为一个缓冲区的开始和结束,即缓冲区的整个生命周 ...

  8. What is the difference between a binary tree, a binary search tree, a B tree and a B+ tree?

    Binary Tree : It is a tree data structure in which each node has at most two children. As such there ...

  9. quotas and disk replace on netapp

    ==================================================================================================== ...

随机推荐

  1. android通过代码判断手机是否root

    只要/system/bin/su./system/xbin/su这两个文件中有一个存在,就表明已经具有ROOT权限,如果两个都不存在,则不具有ROOT权限. // 判断是否具有ROOT权限 publi ...

  2. js中call方法的使用介绍

    js call call 方法 请参阅 应用于:Function 对象 要求 版本 5.5 调用一个对象的一个方法,以另一个对象替换当前对象. call([thisObj[,arg1[, arg2[, ...

  3. linux时间同步,ntpd、ntpdate

    linux时间同步,ntpd.ntpdate 在Windwos中,系统时间的设置很简单,界面操作,通俗易懂.而且设置后,重启,关机都没关系.系统时间会自动保存在Bios的时钟里面,启动计算机的时候,系 ...

  4. rsync unison+inotify双向实时同步

    rsync多线程同步 A:文件服务器 ip:10.10.1.10 B:备份服务器 ip:10.10.1.11 1.在B服务器上安装rsync软件 tar xzvf rsync-3.1.0.tar.gz ...

  5. 浅谈 qmake 之 shadow build

    shadow build shadow build 是什么东西?就是将源码路径和构建路径分开(也就是生成的makefile文件和其他产物都不放到源码路径),以此来保证源码路径的清洁. 这不是qmake ...

  6. TFS 创建分支

    1 2 3 4

  7. JS-日期框、下拉框、全选复选框

    <!-- 下拉框 --><link rel="stylesheet" href="static/ace/css/chosen.css" /&g ...

  8. 使用SQL Server Management Studio 创建作业备份数据库

    在项目中,经常需要备份数据库,如果能做到只需点个按钮(“开始备份数据库”按钮),然后什么都不管,数据库就自动备份好了,或者服务器上的数据库隔一段时间自动备份一次,那该多好啊. Sql server 的 ...

  9. Polycarp's problems

    Polycarp's problems time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  10. 【转】linux grep命令详解

    简介 grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它 ...