题目
题解
STL。
用map实现类似链表的数据结构。
要是会map的话,很简单吧。
代码
#include<bits/stdc++.h>
using namespace std;
struct node {
int FileType;
string FileInfo;
};
int ft;
string op, fn, fi;
map<string,node> OS;
int main()
{
while(cin>>op) {
if(op == "exit") return 0;
else if(op == "create") {
cin>>fn>>ft>>fi;
OS[fn].FileType = ft;
OS[fn].FileInfo = fi;
} else if(op == "open") {
cin>>fn;
while(OS[fn].FileType) { // 找到存储的是数据块的文件
fn = OS[fn].FileInfo;
}
cout << OS[fn].FileInfo << endl;
}
}
return 0;
}