hdu 1413 文件系统
来源:互联网 发布:淘宝开店加盟靠谱吗 编辑:程序博客网 时间:2024/06/05 23:43
#include<iostream>
#include<vector>
#include<string.h>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
struct command{
vector<string>file;//当前目录下的文件
map<string,int> num;//对应当前子目录的编号
vector<command *>next;//指向子目录
command *pre;//指向当前目录的上一级
};
command *root;
int Judge(stringk,vector<string> p){//执行查找
vector<string>::iteratorit;
it=find(p.begin(),p.end(),k);
return it!=p.end();
}
int DElete(string p,string q,command *t){//执行删除和判断
vector<string>::iteratorit;
int x,i;
if(q=="file"){
it=find(t->file.begin(),t->file.end(),p);
t->file.erase(it);
}
else{
x=t->num[p];
for(i=0;i<t->next.size()&&x>0;i++)x--;
if(t->next[i]->dir.size() ||t->next[i]->file.size())
return 0;
it=find(t->dir.begin(),t->dir.end(),p);
t->dir.erase(it);
}
return 1;
}
void make(){
root=new command();
command *h=root,*t;
int x;
while(cin>>p>>q){
if(p=="CD"){//进入一个子目录
if(q==".." || q=="\\"){
cout<<"success"<<endl;
if(q=="..")
h=t->pre;
else
h=root;
}
else if(Judge(q,t->dir)){
cout<<"success"<<endl;
x=t->num[q];
h=t;
}
else{
cout<<"no suchdirectory"<<endl;
}
}
else if(p=="MD"){//创建一个子目录
t=h;
if(q==".." || Judge(q,t->dir)){
cout<<"directory alreadyexist"<<endl;
}
else{
t->dir.push_back(q);
t->num[q]=t->next.size();
command *newafile=new command();
t->next.push_back(newafile);
t=newafile;
t->pre=h;
}
}
else if(p=="RD"){//删除一个子目录
t=h;
if(Judge(q,t->dir)){
if(DElete(q,"dir",t)){
cout<<"success"<<endl;
}
else
cout<<"can not delete thedirectory"<<endl;
}
else{
cout<<"can not delete thedirectory"<<endl;
}
}
else if(p=="CREATE"){//创建一个文件
t=h;
if(Judge(q,t->file)){
}
else
{
t->file.push_back(q);
cout<<"success"<<endl;
}
}
else if(p=="DELETE"){//删除一个文件
t=h;
if(Judge(q,t->file)){
DElete(q,"file",t);
cout<<"success"<<endl;
}
else
}
}
}
int main(){
return 0;
}
- hdu 1413 文件系统
- HDU 1242 Rescue
- ZZULI_SummerPractice(3) HDU 1…
- HDU 1579 Function Run Fun
- HDU 1405 The Last Practice
- HDU 2050 折线分割平面
- hdu 1000 A + B Problem
- HDU 1075 What Are You Talking …
- HDOJ 1171 Big Event in HDU
- hdu 1216 Assistance Required
- hdu 1225 Football Score
- HDU:1060 Leftmost Digit
- HDU 1030 Delta-wave
- HDU 1232 畅通工程
- HDU 2102 A计划
- HDU 4287 Intelligent IME
- hdu 1001 Sum Problem
- hdu 2039 三角形 /…
- hdu 1267 下沙的沙子有几粒?
- hdu 1269 迷宫城堡
- hdu 1285 确定比赛名次
- hdu 1317 XYZZY
- hdu 1332 LC-Display
- hdu 1413 文件系统
- hdu 1427 速算24点
- hdu 1434 幸福列车
- hdu 2005 第几天? java版
- hdu 1854 Q-Sequence
- USACO Milking Cows
- USACO Calf Flac
- 剖析我的五子棋
- hdu 1501 Zipper