中等模拟 | 北邮OJ | 91. 文件系统

版权声明:本文纯属作者口胡,欢迎转载 https://blog.csdn.net/TQCAI666/article/details/86654189

https://vpn.bupt.edu.cn/http/10.105.242.80/problem/p/91/

/*
USER_ID: test#shizhuxiniubi
PROBLEM: 91
SUBMISSION_TIME: 2019-01-26 09:15:04
*/
#include <bits/stdc++.h>
#define FF(a,b) for(int a=0;a<b;a++)
#define F(a,b) for(int a=1;a<=b;a++)
#define LEN 510000
#define INF 1000000
#define bug(x) cout<<#x<<"="<<x<<endl;
 
using namespace std;
 
typedef struct Node{
    string name;
    bool isDir;
    vector<Node*> li;
    Node(string name="",bool isDir=0):name(name),isDir(isDir){}
}Node;
 
map<string,Node*> name2node;
 
void createNode(string name,string dir,bool isDir){
    Node* nd=new Node(name,isDir);
    name2node[name]=nd;
    if(name!="root"){
        Node* p=name2node[dir];
        p->li.push_back(nd);
    }
}
 
void initMap(){
    name2node.clear();
    createNode("root","",1);
}
 
void listNode(string dir,bool isDir){
    vector<Node*> &li=name2node[dir]->li;
    FF(i,li.size()){
        Node* e=li[i];
        if(e->isDir==isDir){
            printf("%s\n",e->name.c_str());
        }
    }
}
 
int main()
{
//    freopen("./in","r",stdin);
    int N;
    scanf("%d",&N);
    while(N--){
        int n;
        scanf("%d",&n);
        initMap();
        while(n--){
            char buf1[1000];
            char buf2[1000];
            char buf3[1000];
            scanf("%s%s",buf1,buf2);
            string s1(buf1),s2(buf2);
            if(s1=="CREATEFILE"){
                scanf("%s",buf3);
                string s3(buf3);
                createNode(s2,s3,0);
            }
            else if(s1=="CREATEDIR"){
                scanf("%s",buf3);
                string s3(buf3);
                createNode(s2,s3,1);
            }
            else if(s1=="LISTFILE"){
                listNode(s2,0);
            }else{
                listNode(s2,1);
            }
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/TQCAI666/article/details/86654189
今日推荐