POJ1057 FILE MAPPING
题目来源:http://poj.org/problem?id=1057
题目大意:计算机的用户通常希望能够看到计算机存储的文件的层次结构的图形化表示。Microsoft Windows的 "Explorer"(文件浏览器)就是这样的应用。在图形界面出现以前,最好的描述文件层级结构的方法是展示一个目录和文件的“map”,来表示文件的目录结构。例如:
ROOT
| DIR1
| File1
| File2
| File3
| DIR2
| DIR3
| File1
File1
File2
上面的实例展示了一个根目录,包含了两个文件和三个子目录,第一个子目录下包含三个文件。子二个子目录为空,第三个子目录含一个文件。
输入:编写一个程序,读入一系列的数据用于表示一个计算机中的文件结构。每个数据集用一个*号来表示结束。整个数据的结束标记为#。数据集中含多个文件和目录。约定文件结构的起始点是root,每个目录的结尾用']'表示。目录名以'd'开头,文件名以'f'开头。文件名可能有扩展名也可能没有扩展名。文件名和目录名不含空格。
输出:对于每个目录先输出其子目录,然后输出包含的文件,文件按字典序输出,每个数据集首先输出一行"DATA SET x:" ,x为数据集序号,从1开始计。每个测试用例之间用空行隔开。每个层级输出一个‘|’后接5个空格。具体见sample。
Sample Input
file1
file2
dir3
dir2
file1
file2
]
]
file4
dir1
]
file3
*
file2
file1
*
#
Sample Output
DATA SET 1:
ROOT
| dir3
| | dir2
| | file1
| | file2
| dir1
file1
file2
file3
file4 DATA SET 2:
ROOT
file1
file2
本题的输出格式要求比较严,要特别小心,另外对于每个目录,文件需要排序,但是对于子目录只需要按出现的顺序输出。
可以递归实现,也可以用栈。代码里用的递归。
////////////////////////////////////////////////////////////////////
// POJ1057 FILE MAPPING
// Memory: 200K Time: 16MS
// Language: C++ Result : Accepted
//////////////////////////////////////////////////////////////////// #include <iostream>
#include <string>
#include <list> using namespace std;
string str; void HandleDir(int layer, string dir_name) {
list<string> file_list; for (int i = ; i < layer; ++i) {
cout << "| ";
}
cout << dir_name << endl;
while (str != "*" && str != "]") {
if (str[] == 'f') {
file_list.push_back(str);
}
else if (str[] == 'd') {
string dir = str;
cin >> str;
HandleDir(layer + , dir);
}
cin >> str;
}
file_list.sort();
for (list<string>::iterator it = file_list.begin(); it != file_list.end(); ++it) {
for (int i = ; i < layer; ++i) {
cout << "| ";
}
cout << *it << endl;
}
} int main(void) { for (int case_id = ; cin >> str, str != "#"; ++case_id) {
cout << "DATA SET " << case_id << ":" << endl;
HandleDir(, "ROOT");
cout << endl;
}
return ;
}
POJ1057 FILE MAPPING的更多相关文章
- File mapping
文件映射的三个功能: 1.File mapping allows the process to use both random input and output (I/O) and sequentia ...
- POJ 1057 File Mapping 最详细的解题报告
题目来源:POJ 1057 File Mapping 题目大意:像我的电脑那样显示文件夹和文件信息,其中在同一级目录内,文件夹排在文件的前面并且文件夹的顺序不变,同一级目录中文件按字母序排列.文件以‘ ...
- OpenJudge 2775 文件结构“图”/ Poj 1057 FILE MAPPING
1.链接地址: http://bailian.openjudge.cn/practice/2775 http://poj.org/problem?id=1057 2.题目: 总时间限制: 1000ms ...
- Creating a File Mapping Object
创建一个文件映射对象 映射一个文件的第一步是通过调用CreateFile函数来打开一个文件.为了确保其他的进程不能对文件已经被映射的那一部分进行写操作,你应该以唯一访问(exclusive acces ...
- Delphi Memory-Mapped File简单示例
{ Copyright ?1999 by Delphi 5 Developer's Guide - Xavier Pacheco and Steve Teixeira } unit MainFrm; ...
- Analysis about different methods for reading and writing file in Java language
referee:Java Programming Tutorial Advanced Input & Output (I/O) JDK 1.4+ introduced the so-calle ...
- File System Programming---(三)
Accessing Files and Directories Before you can open a file, you first have to locate it in the file ...
- The Portable Executable File Format from Top to Bottom(每个结构体都非常清楚)
The Portable Executable File Format from Top to Bottom Randy KathMicrosoft Developer Network Technol ...
- Windows API Hooking in Python
catalogue . 相关基础知识 . Deviare API Hook Overview . 使用ctypes调用Windows API . pydbg . winappdbg . dll inj ...
随机推荐
- Linux reboot后数据库无法自动启动
需将以下由N改为Y orcl:/data/oracle_db/product/13.2.0/db_1:Y Last login: Thu Aug 27 16:36:19 2015 from 10.10 ...
- phper 需要学习js
- php中用大括号把?>和<?php框起来的作用
<?php function my_function() { ?> My function was called <!--就是这里,为什么前面要用?>和< ?php 把M ...
- php的变量引用详解
<?php class SimpleClass { // property declaration public $var = 'a default value'; // method decl ...
- 关于MySQL隐式转换
一.如果表定义的是varchar字段,传入的是数字,则会发生隐式转换. 1.表DDL 2.传int的sql 3.传字符串的sql 仔细看下表结构,rid的字段类型: 而用户传入的是int,这里会有一个 ...
- R: 对向量中的每个元素,检查其是否包含某个“单词”
#检测一个字符串中,是否包含某个子串,是返回T,否返回Frequire(stringr) require(stringr) test <- c("这里有天气热敏感冒",&qu ...
- Postman工具---请求与响应
参考:http://blog.csdn.net/water_0815/article/details/53311561
- Excel打开图片
=HYPERLINK("D:\固定资产图片\"&C2&".jpg",C2)
- Ubuntu16.04版安装VMwareTools的步骤和没法挂载目录问题的解决
vmtool安装流程 1.点击vmware 里面的虚拟机——>安装vmware tool 2.然后(等待一会)弹出一个界面把里面的 VMwareTools-9.6.1-1378637.tar.g ...
- Chrome Plugin Recommendation
1.AdBlock 拦截广告神器 2.IPBlade 变更IP地址,使你自由 3.JSON-handle 让接口返回的JSON数据更好看 4.Proxy SwitchyOmega 变更浏览器代理 5. ...