权限查询

给爷写吐了,这个模拟真的恶心。

#include<iostream>
#include<vector>
#include<unordered_map>
#include<sstream>

using namespace std;

const int N = 110;
int p, r, u, q;
struct {
    string name;
    vector<pair<string, int>>v;
}js[N];
struct { string name; vector<string>v; }boss[N];
unordered_map<string, int> m;

pair<string, int>get(string s) {
    int i = 0;
    while (i < s.size() && s[i] != ':')i++;
    if (i == s.size())return { s,-1 };
    string t = s.substr(0, i);
    return { t,s.back() - '0' };
}


void fun() {
    int type = -1;
    int mx = -1;//最高权限
    string s1, s2;
    cin >> s1 >> s2;
    pair<string, int>pp = get(s2);
    if (pp.second == -1) {
        if (m[pp.first] == -1) {
            type = 1;
            //输出有无权限
        }
        else {
            //输出最高权限
            type = 2;
        }
    }
    else {
        if (m[pp.first] == -1) {
            cout << "false" << endl;
            return;
        }
        else {
            //查询是否具有相应等级
            type = 3;
        }
    }
    for (int i = 0; i < u; i++) {
        if (boss[i].name == s1) {
            for (string xjs : boss[i].v) {
                for (int j = 0; j < r; j++) {
                    if (xjs == js[j].name) {
                        for (pair<string, int>p : js[j].v) {
                            //cout<<p.first<<endl;
                            if (p.first == pp.first) {
                                if (type == 1) {
                                    cout << "true" << endl;
                                    return;
                                }
                                else if (type == 2) {
                                    mx = max(mx, p.second);
                                }
                                else if (type == 3) {
                                    if (p.second >= pp.second) {
                                        cout << "true" << endl;
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (mx!=-1)cout << mx << endl;
    else cout << "false" << endl;
}

int main() {
    string s;
    stringstream ss;
    cin >> p;
    getchar();
    while (p--) {
        getline(cin, s);
        int i = 0;
        pair<string, int>p = get(s);//不是权限返回-1
        m[p.first] = p.second;
    }
    cin >> r;
    getchar();
    for (int x = 0; x < r; x++) {
        getline(cin, s);
        ss.clear();
        ss.str(s);
        ss >> js[x].name;
        int n;
        ss >> n;
        for (int i = 0; i < n; i++) {
            string t;
            ss >> t;
            pair<string, int>p = get(t);
            js[x].v.push_back(p);
        }
    }
    cin >> u;
    getchar();
    for (int i = 0; i < u; i++) {
        getline(cin, s);
        ss.clear();
        ss.str(s);
        ss >> boss[i].name;
        int n;
        ss >> n;
        for (int j = 0; j < n; j++) {
            string t;
            ss >> t;
            boss[i].v.push_back(t);
        }
    }
    cin >> q;
    while (q--) {
        fun();
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值