CCF CSP 202206-3角色授权【70分】

#include<bits/stdc++.h>
using namespace std;
struct Res{
    vector<string> op;      //操作
    vector<string> res_type;//资源种类 
    vector<string> res_name;//资源名称描述 
};
map<string, vector<string> >group2role;
map<string, vector<string> >user2role;
map<string, Res >roles;
//判断role 能否提供操作类型op,资源种类tp,资源名称name的权限
bool check(string op,string tp,string name,string role) {
    Res res=roles[role];
    bool ok=false;
    for(auto o:res.op) {
        if(o=="*"||o==op) {ok=true;break;}
    }
    if(ok==false) return false;
    ok=false;
    for(auto t:res.res_type) {
        if(t=="*"||t==tp) {ok=true;break;}
    }
    if(ok==false) return false;
    ok=false;
    if(res.res_name.size()==0) return true;
    for(auto na:res.res_name) {
        if(na==name) {ok=true;break;}
    }
    return ok;
}
int main() {
    int n,m,q;
    cin>>n>>m>>q;
    for(int i=0;i<n;i++) {
        string str,tmp;
        Res r;
        cin>>str;
        int nv,no,nn;
        cin>>nv;
        for(int j=0;j<nv;j++) {
            cin>>tmp;
            r.op.push_back(tmp);
        }
        cin>>no;
        for(int j=0;j<no;j++) {
            cin>>tmp;
            r.res_type.push_back(tmp);
        }
        cin>>nn;
        for(int j=0;j<nn;j++) {
            cin>>tmp;
            r.res_name.push_back(tmp);
        }
        roles[str]=r;
    }
    

    for(int i=0;i<m;i++) {
        string str,tmp,tp;
        int ns;
        cin>>str>>ns;
        for(int j=0;j<ns;j++) {
            cin>>tp>>tmp;
            if(tp=="g") {
                group2role[tmp].push_back(str);
            } else {
                user2role[tmp].push_back(str);
            }
        }
    }

    for(int i=0;i<q;i++) {
        vector<string>groups;
        string user;
        int ng;
        bool ok=false;
        cin>>user>>ng;
        for(int j=0;j<ng;j++) {
            string tmp;
            cin>>tmp;
            groups.push_back(tmp);
        }
        string op,tp,name;
        cin>>op>>tp>>name;
        // 遍历关联user的所有角色
        for(auto role:user2role[user]) {
            if(check(op,tp,name,role)) {ok=true;break;}
        }
        for(auto group:groups) {
            for(auto role:group2role[group]) {
                if(check(op,tp,name,role)) {ok=true;break;}
            }
        }
        if(ok) cout<<1<<endl;
        else cout<<0<<endl;
    }
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值