POJ 1057 FILE MAPPING

1. 这道题根本不会做,直接看的别人的解体报告,看了别人的解题报告的算法说明,还是不会做,只好看代码了;

2. 这篇博客写得比我写得好(http://jovesky.info/blog/2011/08/12/poj-1057-file-mapping-c-edition/),我就是看人家的看懂的;

3. 递归+vector,一层套一层,以后还得看看怎么做的。现在思路会了,但是vector还是不会用,上午刚看了primer还是不会用,另外细节问题很繁琐,日后就是为了学递归也得再做一遍这道题。




#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

struct node
{
    vector<string> file;
    vector<node> dir;
    string name;
};
int end = 0;
void fileinput(node &now)
{
    string tmp;
    while (1)
    {
        cin >> tmp;
        if (tmp[0] == '#')
        {
            end = 1;
            break;
        }
        else if (tmp[0] == 'f')
            now.file.push_back(tmp);
        else if (tmp[0] == 'd')
        {
            node d;
            d.name = tmp;
            fileinput(d);
            now.dir.push_back(d);
        }
        else break;
    }
    sort(now.file.begin(), now.file.begin() + now.file.size());
    return;
}

void fileoutput(node now, int n)
{
    int i, j;
    for (i = 0; i < n; i++)
        cout << "|     ";
    cout << now.name << endl;
    for (i = 0; i < (int)now.dir.size(); i++)
        fileoutput(now.dir[i], n + 1);
    for (i = 0; i < (int)now.file.size(); i++)
    {
        for (j = 0; j < n; j++)
            cout << "|     ";
        cout << now.file[i] << endl;
    }
    return;
}



int main()
{
    int cases = 1;
    while (cases)
    {
        node root;
        root.name = "ROOT";
        fileinput(root);
        if (end)
            break;
        cout << "DATA SET " << cases << ':' << endl;
        fileoutput(root, 0);
        cases++;
        cout << endl;
    }
    return 0;
}


posted on 2012-03-28 16:52  赵乐ACM 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/dollarzhaole/archive/2012/03/28/3188929.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值