权限查询(CCF201612-3)

传送门

题解:雷少的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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值