Directory Listing(zoj 1635)
来源:互联网 发布:珠海博明视觉 知乎 编辑:程序博客网 时间:2024/04/29 12:05
Directory Listing
Time Limit: 1 Second Memory Limit: 32768 KB
Given a tree of UNIX directories and file/directory sizes, you are supposed to list them as a tree with proper indention and sizes.
Input
The input consists of several test cases. Each case consists of several lines which represent the levels of the directory tree. The first line contains the root file/directory. If it is a directory, then its children will be listed in the second line, inside a pair of parentheses. Similarly, if any of its children is a directory, then the contents of that directory will be listed in the next line, inside a pair of parentheses. The format of a file/directory is:
name size or *name size
where name, the name of the file/directory, is a string of no more than 10 characters; size > 0 is the integer size of the file/directory; * means the name is a directory. It is guaranteed that name will not contain characters '(', ')', '[', ']', and '*'. There are no more than 10 levels for each case, and no more than 10 files/directories on each level.
Output
For each test case, list the tree in the format shown by the sample. Files/directories that are of depth d will have their names indented by 8d spaces. Do NOT print tabs to indent the output. The size of a directory D is the sum of the sizes of all the files/directories in D, plus its own size.
Sample Input
*/usr 1(*mark 1 *alex 1)(hw.c 3 *course 1) (hw.c 5)(aa.txt 12)*/usr 1()
Sample Output
|_*/usr[24] |_*mark[17] | |_hw.c[3] | |_*course[13] | |_aa.txt[12] |_*alex[6] |_hw.c[5]|_*/usr[1]
Author: CHEN, Yue
Source: Zhejiang University Local Contest 2003
有点烦的模拟题..
#include<iostream>
using namespace std;
struct
{
char name[ 15 ];
int next[ 15 ];
int num;
int key;
void Init(){ num = 0 ;}
}f[ 150 ];
int tn;
void Add(int index,int& pos,char *str)
{
int i,len=0;
int z;
char s[ 200 ];
for(i=pos;str[i] != ' ' && str[i] !=')' ;i++)s[ len++ ] = str[i];
if( len == 0 )return ;
s[ len ] = 0;
f[ index ].next[ f[index].num ] = tn;
f[ index ].num++;
strcpy( f[ tn ].name ,s );
f[ tn ].Init();
z = 0;
for(i++;str[i] !=' ' && str[i] != ')';i++)
{
z += str[i] - 48;
z*=10;
}
f[ tn ].key = z/10;
tn++;
pos = i;
}
void dfs1(int pos)
{
for(int i=0;i<f[pos].num;i++)
{
dfs1(f[pos].next[i]);
}
int z = 0;
for(int i=0;i<f[pos].num;i++)
{
z += f[ f[pos].next[i] ].key ;
}
f[ pos ].key += z;
}
int len;
void dfs2(int pos,int d,int a[])
{
if( d )printf(" ");
for(int i=1;i<8*d;i++)
{
if(a[i])printf("|");
else printf(" ");
}
printf("|_%s[%d]/n",f[pos].name,f[pos].key);
for(int i=0;i<f[pos].num;i++)
{
if( i + 1 != f[pos].num )a[ 8 * (d + 1 )] = 1 ;
dfs2( f[ pos ].next[ i ],d+1 ,a);
a[ 8 * (d+1) ] = 0;
}
}
int main()
{
char s[ 200 ];
int pre,tp;
int i,j;
int a[ 2500 ];
while( gets(s) )
{
if( s[0] != '(' )
{
f[ 0 ].Init();
tn = 1;
for(i=0;s[i] != ' ';i++)
f[ 0 ].name[i] = s[i];
f[ 0 ].name[i]=0;
tp = 0;
for(i++;s[i];i++)
tp += s[i] - 48,tp*=10;
f[0].key = tp/10;
if( s[0] != '*' )
{
printf("|_%s[%d]/n",f[0].name,tp/10);
continue;
}
gets(s);
}
i = 0;
pre = tn;
while( 1 )
{
for(j=1;s[j];j++ )
{
if( s[j] == ' ' )continue;
if( s[j] == '(' )continue;
Add(i,j,s);
if( s[j] == ')' )
{
i++;
while( i <= pre && f[i].name[0] != '*' )i++;
}
}
i = pre;
while( i < tn && f[i].name[0] != '*' )i++;
if( i == tn )break;
pre = tn;
gets(s);
}
memset(a,0,sizeof(a) );
dfs1(0);
dfs2(0,0,a);
}
}
- Directory Listing(zoj 1635)
- Directory Listing
- 题目:1635 Directory Listing(列出目录)
- Tomcat 开启 Directory Listing
- Directory Listing Denied
- Tomcat之Directory Listing
- Tomcat 如何允许directory listing
- 更改Tomcat 'Directory Listing For' method
- Tomcat 5.5 显示Directory Listing的问题
- 更改 Tomcat 'Directory Listing For' method
- How to enable directory listing in tomcat
- tomcat安全配置之禁用Directory Listing
- Listing only directory using ls in bash
- 出现Directory Listing Denied的原因和解决方法
- Directory Listing For解决方法-tomcat启动,首页报错
- 解决IIS错误:Directory Listing Denied This Virtual Directory does not allow contents to be listed.
- Directory Listing Denied This Virtual Directory does not allow contents to be listed.
- 打开网站提示HTTP错误:Directory Listing Denied This Virtual Directory does not allow contents to be list.
- 关于一道面试题,使用C#实现字符串反转算法
- XPath
- 编程中的命名设计那点事
- 给刚参加工作的大学生十点建议
- 谁有遗传算法在生产调度上的应用实例啊!!!
- Directory Listing(zoj 1635)
- 用了一段时间的 Vista,换回 XP 算了
- Windows Via C/C++ 读书笔记 7 异步IO, 完成端口模式
- 深入理解Servlet/JSP之“Cookie和Session原理
- Symbian 活动对象彻底理解
- 大连Oracle10g OCP培训认证 提升职场竞争力
- 细说电子商务专业
- Command Line Arguments in C++
- 全面解析Oracle认证及如何准备考试