//已经测试过了最后的示例和题目的示例,还是找不出问题,先放到这里吧
#include<iostream>
#include<vector>
#include<map>
#include<string>
using namespace std;
struct Root{
string name;
int level;
};
const int maxn=101;
Root roots[maxn];
vector<Root> roles[maxn];
vector<string> users[maxn];
map<string,int> to_role;
map<string,int> to_user;
Root get_root(string &buff){
Root tmp;
int index=buff.find(':');
if(index==-1){
tmp.name =buff;
tmp.level =-1;
}
else{
tmp.name=buff.substr(0,index);
tmp.level=stoi(buff.substr(index+1));
}
return tmp;
}
int p,r,u,q;
map<string,int> ::iterator it;
void test(){
for(int i=0;i<p;i++){
cout<<roots[i].name <<":"<<roots[i].level<<endl;
}
cout<<endl;
for(int i=0;i<r;i++){
for(int j=0;j<roles[i].size() ;j++){
cout<<roles[i][j].name<<":"<<roles[i][j].level<<" ";
}
cout<<endl;
}
cout<<endl;
for(int i=0;i<u;i++){
for(int j=0;j<users[i].size();j++){
cout<<users[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
it=to_user.begin() ;
while(it !=to_user.end()){
cout<<it->first<<" "<<it->second<<endl;
it++;
}
cout<<endl;
it=to_role.begin() ;
while(it !=to_role.end()){
cout<<it->first<<" "<<it->second<<endl;
it++;
}
cout<<endl;
}
int main(){
Root tmp;
string buff;
cin>>p;
for(int i=0;i<p;i++){
cin>>buff;
tmp=get_root(buff);
roots[i]=tmp;
}
cin>>r;
for(int i=0;i<r;i++){
cin>>buff;
to_role[buff]=i;
cin>>buff;
int num=stoi(buff);
for(int j=0;j<num;j++){
cin>>buff;
tmp=get_root(buff);
roles[i].push_back(tmp);
}
}
cin>>u;
for(int i=0;i<u;i++){
cin>>buff;
to_user[buff]=i;
cin>>buff;
int num=stoi(buff);
for(int j=0;j<num;j++){
cin>>buff;
users[i].push_back(buff);
}
}
//test();
cin>>q;
string name,root;
// cout<<"q:"<<q<<endl;
for(int i=0;i<q;i++){
cin>>name>>root;
it=to_user.find(name);
if(it==to_user.end()){
cout<<"false"<<endl;
continue;
}
int u=it->second;
Root sroot=get_root(root);
bool flag=0;
int max=-1;
for(int j=0;j<users[u].size() ;j++){
int roles_index=to_role[users[u][j]];
int root_num=roles[roles_index].size();
int k=0;
for(;k<root_num;k++){
tmp=roles[roles_index][k];
if(sroot.name ==tmp.name ){
if(sroot.level==-1){
if(tmp.level !=-1){
if(max<tmp.level ) max=tmp.level ;
flag=1;
}
else {
flag=1;
cout<<"true"<<endl;
break;
}
}
else if( tmp.level >=sroot.level ){
cout<<"true"<<endl;
flag=1;
break;
}
}
}
}
if(flag==0) cout<<"false"<<endl;
if(flag==1&&max!=-1) cout<<max<<endl;
}
return 0;
}
/*样例输入:
3
crm:2
git:3
game
4
hr 2 crm:2 crm:1
it 3 crm:1 git:1 game
dev 2 git:3 game
qa 1 git:0
4
alice 2 hr it
bob 2 it qa
charlie 1 dev
sunpro 1 qa
10
alice game
alice crm:2
bob git
bob poweroff
charlie game
charlie crm
charlie git:0
malice game
sunpro git
alice crm
样例输出结果:
true
true
1
false
true
false
true
false
0
2
201912-3 CSP 40分之谜
最新推荐文章于 2023-02-22 19:03:10 发布