zoukankan      html  css  js  c++  java
  • 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;
    }
    


  • 相关阅读:
    python爬虫实战(八)--------知乎
    python爬虫实战(七)--------伯乐在线文章(模版)
    python分布式爬虫打造搜索引擎--------scrapy实现
    VS2010与SVN
    ASP.net 自定义控件GridView
    Asp.net Ajax提供PageMethods调用
    JSON串行化
    JOSN反串行化
    WebRequestManager对象的使用
    WebRequest调用
  • 原文地址:https://www.cnblogs.com/dollarzhaole/p/3188929.html
Copyright © 2011-2022 走看看