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 ...
随机推荐
- 问题:C#属性;结果:c# 属性
c# 属性 属性:get { //读属性代码 } set { //写属性代码 } public class Person{private string name;public string Name{ ...
- 文本框控件JTextField和JTextArea的使用
-----------------siwuxie095 工程名:TestUI 包名:com.siwuxie095.ui 类名:TestTextF ...
- ASCII / Unicode / UTF-8 / GBK
1 ASCII ASCII(American Standard Code for Information Interchange,美国标准信息交换代码)是基于拉丁字母的一套电脑编码系统,主要用于显示现 ...
- PCL—点云分割(超体聚类) 低层次点云处理
博客转载自:http://www.cnblogs.com/ironstark/p/5013968.html 1.超体聚类——一种来自图像的分割方法 超体(supervoxel)是一种集合,集合的元素是 ...
- 算法Sedgewick第四版-第1章基础-003一封装日期
1. package ADT; import algorithms.util.StdOut; /**************************************************** ...
- 数字图像处理实验(6):PROJECT 04-02,Fourier Spectrum and Average Value 标签: 图像处理MATLABfft 2017-05-07 23:1
实验要求: Objective: To observe the Fourier spectrum by FFT and the average value of an image. Main requ ...
- Luogu 3704 [SDOI2017]数字表格
列一下式子: $\prod_{i = 1}^{n}\prod_{j = 1}^{m}fib_{gcd(i, j)}$ 很套路的变成这样: $\prod_{d = 1}^{min(n, m)}fib_{ ...
- vue 之 计算属性和侦听器
计算属性 模板内的表达式非常便利,但是设计它们的初衷是用于简单运算的.在模板中放入太多的逻辑会让模板过重且难以维护.例如: <div> {{ message.split('').rever ...
- scala中的self type
scala目前的书籍有两<快学scala>和<scala编程>.资料确实不多,对这个语法使用只能结合使用进行理解. 先看源码: private[spark] trait Act ...
- 数据结构 Job
问题描述 有 n 项工作在等待队列中等待处理,编号为 1-n. 每个工作有个优先级 p.处理机同一时间只能处理一项工作.处理机决定接下来处理哪一项工作的方式为:从队首取出一项工作 x,若等待队列中没有 ...