题解:雷少的STL真的玩的太厉害了,雷少是我见过现实版身边最励志的人,很刻苦,很玩命,像雷少学习。
开始正解:这个题使用三个map即可,第一个map存储权限,第二个map存储角色,value存储权限数组,第三个map存储使用者,然后直接进行模拟即可。
附上代码:
#include<bits/stdc++.h>
using namespace std;
map<string,int> cat;
typedef pair<string,int> PI;
map<string,vector<PI> > role;
map<string,vector<string> > user;
PI trans_form(string s){
if(s.find(":")==string::npos){
return make_pair(s,-999);
}
int t=0;
int i;
for(i=0;s[i];i++){
if(s[i]==':'){
break;
}
}
string p=s.substr(0,i);
for(int j=i+1;s[j];j++){
t=t*10+s[j]-'0';
}
return make_pair(p,t);
}
int main(){
int p;
string s;
cin>>p;
while(p--){
cin>>s;
cat.insert(trans_form(s));
}
int r;
cin>>r;
while(r--){
int cnt;
string rol;
cin>>rol>>cnt;
while(cnt--){
cin>>s;
role[rol].push_back(trans_form(s));
}
}
int u;
cin>>u;
while(u--){
int cnt;
string us;
cin>>us>>cnt;
while(cnt--){
cin>>s;
user[us].push_back(s);
}
}
int q;
cin>>q;
while(q--){
string us;
cin>>us>>s;
PI p;
p=trans_form(s);
int ans=-9999;
int len=user[us].size();
for(int i=0;i<len;i++){
string rol=user[us][i];
int len2=role[rol].size();
for(int j=0;j<len2;j++){
if(role[rol][j].first==p.first){
ans=max(ans,role[rol][j].second);
}
}
}
if(p.second==-999&&cat[p.first]!=-999){
if(ans!=-9999){
cout<<ans<<endl;
}else{
cout<<"false"<<endl;
}
}
if(cat[p.first]!=-999&&p.second!=-999){
if(ans>=p.second) cout<<"true"<<endl;
else cout<<"false"<<endl;
}
if(cat[p.first]==-999&&p.second==-999){
if(ans!=-9999) cout<<"true"<<endl;
else cout<<"false"<<endl;
}
}
return 0;
}