ccf 201612-3 权限查询

该博客探讨了如何将权限与每个用户精确匹配的问题,提供了链接(http://118.190.20.162/view.page?gpid=T50)以便读者深入研究。
摘要由CSDN通过智能技术生成

http://118.190.20.162/view.page?gpid=T50
把权限对应到每一个用户中去

#include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;
struct T{
    map<string,int> t;
};
struct V{
    vector<string> t;
};
map<string,T> all;
map<string,int> AA;
map<string,V> rol;
int main()
{
    string str;
    int n;
    cin >> n;
    while (n--) {//AA
        cin >> str;
        int indx = str.find(':');
        if (indx != string::npos)
            AA[string(str, 0, indx)]=str[indx + 1] - '0';
        else
            AA[str] = -1;
    }
    cin >> n;
    int nu;
    string str2;
    while (n--) {//role
        cin >> str >> nu;
        while (nu--) {
            cin >> str2;
            rol[str].t.push_back(str2);
        }
    }
    cin >> n;
    while (n--) {
        cin >> str>>nu;

        while (nu--) {
            cin >> str2;
            for (vector<string>::iterator it = rol[str2].t.begin();
                it != rol[str2].t.end(); ++it) {
                int indx = it->find(':');
                if (indx != string::npos) {
                    if(all[string(*it, 0, indx)].t[str]<(*it)[indx + 1] - '0' + 1)
                        all[string(*it, 0, indx)].t[str]=(*it)[indx + 1] - '0' + 1;
                }
                else
                    all[*it].t[str] = -1;
            }
        }
    }
    cin >> n;
    string _nam;
    int _le;
    while (n--) {
        cin >> str >> str2;
        int indx = str2.find(':');
        if (indx != string::npos) {
            _nam = string(str2, 0, indx);
            _le = str2[indx + 1] - '0' + 1;
        }
        else {
            _nam = str2;
            _le = -1;
        }
        if (!all[_nam].t[str] || _le > all[_nam].t[str]) { cout << "false" << endl; }
        else if (AA[_nam] != -1 && _le == -1) {
            if (all[_nam].t[str])
                cout << all[_nam].t[str] - 1 << endl;
            else
                cout << "false" << endl;
        }
        else cout << "true" << endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值