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 ...
随机推荐
- Webrtc服务器搭建<转>
http://blog.csdn.net/zqf_office/article/details/49851209
- 每天一道算法题(12)——和为n的连续正数序列或者随机数
题目:输入一个正数n,输出所有和为n 连续正数序列.例如输入15,由于1+2+3+4+5=4+5+6=7+8=15,所以输出3 个连续序列1-5.4-6 和7-8. 1.思路 尊崇以下策略: (1)对 ...
- Jsonp实现跨域请求Ajax
客户端 #!/usr/bin/env python import tornado.ioloop import tornado.web class MainHandler(tornado.web.Req ...
- MSSQL 数据库日志爆涨
解决方法有两种,现只用最简单的方法: 1.数据库属性----选项----恢复模式由完整改为简单--确定 2.右击数据库---任务---收缩 3.数据库属性----选项----恢复模式由简单改为完整-- ...
- Tensorflow梯度下降应用
import tensorflow as tfimport numpy as np #使用numpy生成随机点x_data = np.random.rand(100)y_data = x_data*0 ...
- p2234&bzoj1588 营业额统计
传送门 题目 营业额统计 Tiger最近被公司升任为营业部经理,他上任后接受公司交给的第一项任务便是统计并分析公司成立以来的营业情况. Tiger拿出了公司的账本,账本上记录了公司成立以来每天的营业额 ...
- Luogu 4552 [Poetize6] IncDec Sequence
在BZOJ上好像被权限掉了. 考虑差分,定义差分数组$b$ $$b_i = \left\{\begin{matrix} a_i \ \ \ (i == 1)\\ a_i - a_{i - 1}\ \ ...
- 4.传统的MVC
通过document view设计,我们把应用程序的状态(clicktimes)从一个简单的类设计中抽取出来.下一个目标是抽取转化主要的事件(这个例子里面是鼠标点击之后释放)为应用程序逻辑从而改变应用 ...
- 自定义select样式
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- Linux修改MySQL max_allowed_packet 值
修改配置文件 vi /etc/my.cnf change "max_allowed_packet = 1M" to "max_allowed_packet = 32M&q ...