poj 1057 FILE MAPPING(递归)
来源:互联网 发布:淘宝卖家常用工具 编辑:程序博客网 时间:2024/05/22 16:00
FILE MAPPING
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 2564 Accepted: 1213
Description
It is often helpful for computer users to see a visual representation of the file structure on their computers. The "explorer" in Microsoft Windows is an example of such a system. Before the days of graphical user interfaces, however, such visual representations were not possible. The best that could be done was to show a static "map"of directories and files, using indentation as a guide to directory contents. For example:
This shows that the root directory contains two files and three subdirectories. The first subdirectory contains 3 files, the second is empty and the third contains one file.
ROOT|DIR1| File1|File2|File3|DIR2|DIR3|File1File1File2
This shows that the root directory contains two files and three subdirectories. The first subdirectory contains 3 files, the second is empty and the third contains one file.
Input
Write a program that reads a series of data sets representing a computer file structure. A data set ends with a line containing a single *, and the end of valid data is denoted by a line containing a single #. The data set contains a series of file and directory names. (The root directory is assumed to be the starting point.) The end of a directory is denoted by a ']' Directory names begin with a lower case 'd' and file names begin with a lower case 'f' File names may or may not have an extension (such as fmyfile.dat or fmyfile). File and directory names may not contain spaces.
Output
Note that the contents of any directory should list any subdirectories first, followed by files, if any. All files should be in alphabetical order within each directory. Note that each data set output is marked by the label "DATA SET x:" where x denotes the number of the set, beginning at 1. Note also the blank line between the output data sets. Each level of indentation should show a '|' followed by 5 spaces.
Sample Input
file1file2dir3dir2file1file2]]file4dir1]file3*file2file1*#
Sample Output
DATA SET 1:ROOT| dir3| | dir2| | file1| | file2| dir1file1file2file3file4DATA SET 2:ROOTfile1file2
tips:一点都不喜欢做这样的题目,输入搞得我很乱。
ss每次输入的字符按串,因为每次到dir时才会有递归,dir为dir文件名
s临时字符串变量,用于临时代替ss的值,已更新ss字符串
#include<iostream>#include<cstring>#include<string>#include<algorithm>#include<vector>using namespace std;string ss;void dfs(int depth,string dir){for(int i=0;i<depth;i++)cout<<"| ";vector<string>file;cout<<dir<<endl;string s;while(true){if(ss[0]==']'||ss[0]=='*')break;else if(ss[0]=='f')file.push_back(ss);else s=ss,cin>>ss,dfs(depth+1,s);cin>>ss;} sort(file.begin(),file.end());for(int i=0;i<file.size();i++){for(int i=0;i<depth;i++)cout<<"| ";cout<<file[i]<<endl;}}int main(){for(int i=1;cin>>ss,ss!="#";i++){cout<<"DATA SET "<<i<<":"<<endl;dfs(0,"ROOT");cout<<endl;}return 0; }
阅读全文
0 0
- poj 1057 FILE MAPPING(递归)
- [递归]poj 1057 FILE MAPPING
- POJ 1057 FILE MAPPING
- poj 1057-File mapping
- POJ 1057 FILE MAPPING
- POJ 1057 FILE MAPPING 笔记
- POJ 1057 FILE MAPPING(文件结构图)
- Mapping File
- file mapping
- File Mapping
- File Mapping
- 3-Hibernate mapping file
- DLL file mapping
- File Mapping析疑
- File Mapping析疑
- File mapping的用法
- 【转】File Mapping技术
- redis file mapping
- 数据库的控制功能
- Dubbo总结和使用
- 9月8日云栖精选夜读:杭城上演阿里巴巴“春运”大片……
- Java 之 FileReader FileInputStream InputStreamReader BufferedReader 作用与区别
- 有趣的安全游戏--哈密顿行动(二)不该存在的配置文件
- poj 1057 FILE MAPPING(递归)
- Spring mvc 文件上传接口报错
- linux tar (打包.压缩.解压缩)命令说明 | tar如何解压文件到指定的目录?
- MYSQL中日期精确到日
- Git------Commit和Push的区别
- Java程序中自动导入MYSQL数据库程序
- DOM节点删除之empty和remove区别
- html中实现添加水印的功能
- eclipse第三方安装包的导入