博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ-1057 FILE MAPPING 恶心模拟
阅读量:7253 次
发布时间:2019-06-29

本文共 1466 字,大约阅读时间需要 4 分钟。

题意:介绍一种控制台下的文件目录输出格式,要求进行模拟.详见代码

代码如下:

#include 
#include
#include
#include
#include
#include
#include
#include
using namespace std;/* 目测应该要抽象出文件和目录这两个结构 对于文件我们可以有一个很清醒的认识,也就是说所 有的文件总是离不开目录存在,同一目录下,文件按 照字典序来排列且文件总是放在所有子目录的下面 而目录则严格按照出现的先后顺序来排列 文件先用一个栈来保存,每次记录深度和文件名称 */struct File { int deep; string name; }info;stack
stk;vector
v;void display(int deep) { v.clear(); while (!stk.empty()) { if (stk.top().deep == deep) { string str = stk.top().name; v.push_back(str); stk.pop(); } else { break; } } sort(v.begin(), v.end()); for (vector
::iterator it = v.begin(); it != v.end(); ++it) { for (int i = 0; i < deep; ++i) { printf("| "); } cout << *it << endl; }}int main() {// freopen("1.in", "r", stdin);// freopen("1.out", "w", stdout); char op[200]; int ca = 0, start = 1, first = 1, deep = 0; // deep 用来标记目录的层次 while (scanf("%s", op), op[0] != '#') { // '#'为结束 标记符号 if (start) { if (!first) puts(""); printf("DATA SET %d:\nROOT\n", ++ca); first = start = 0; } if (op[0] == '*') { start = 1; display(deep); } else if (op[0] == 'f') { info.deep = deep; info.name = string(op); // 获得当前这个文件的信息 stk.push(info); // 将这个文件压栈 } else if (op[0] == 'd') { ++deep; for (int i = 0; i < deep; ++i) { printf("| "); } // 对于子目录,直接输出 printf("%s\n", op); } else { display(deep); --deep; } } return 0;}

 

转载于:https://www.cnblogs.com/Lyush/archive/2013/01/05/2846824.html

你可能感兴趣的文章
软件测试全职以及兼职平台以及薪酬报价
查看>>
Javascript:日期排班功能实现
查看>>
git push之后回滚(撤销)代码
查看>>
数组,字符串互相转化
查看>>
linux centos下配置静态ip地址
查看>>
Maven学习总结(三)——使用Maven构建项目
查看>>
Computer Vision & MultiMedia 相关国际会议汇总
查看>>
vs2008在win7系统中安装不问题
查看>>
HDU-1520 Anniversary party
查看>>
springmvc web.xml配置之 -- ContextLoaderListener
查看>>
java_数组作缓存池的不可变类实例
查看>>
webservice主流框架Axis、Axis2、XFire、CXF的比较
查看>>
lambda
查看>>
Master Nginx(3) - Using the Mail Module
查看>>
4、jeecg 笔记之 自定义显示按钮 (exp 属性)
查看>>
大白话5分钟带你走进人工智能-第二十八节集成学习之随机森林概念介绍(1)
查看>>
ASPNET MVC Error 403.14
查看>>
redis学习笔记
查看>>
排球计分规则
查看>>
xml解析
查看>>