201912-3 CSP 40分之谜

//已经测试过了最后的示例和题目的示例,还是找不出问题,先放到这里吧
#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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值