#include<bits/stdc++.h> using namespace std; set<string> private_names; set<string> private_levels; struct role{ set<string> private1; map<string,int> private2; }; map<string,role> map1; map<string,vector<string> > map2; int main(){ ios::sync_with_stdio(0); int x1; cin >> x1; for(int i = 0;i < x1;i++){ string s2;cin >> s2; int index = -1; for(int p = 0;p < s2.length();p++){ if(s2[p] == ':'){ index = p; break; } } if(index == -1){ private_names.insert(s2); } else{ string p_name_1 = ""; for(int p = 0;p < index;p++){ p_name_1 += s2[p]; } private_levels.insert(p_name_1); // int level = s2[index+1] - '0'; // map1[r_name].private2[p_name_1] = level; } } int x2;cin >> x2; for(int i = 0;i < x2;i++){ string r_name;cin >> r_name; int k;cin >> k; for(int j = 0;j < k;j++){ string s2;cin >> s2; int index = -1; for(int p = 0;p < s2.length();p++){ if(s2[p] == ':'){ index = p; break; } } if(index == -1){ map1[r_name].private1.insert(s2); } else{ string p_name_1 = ""; for(int p = 0;p < index;p++){ p_name_1 += s2[p]; } int level = s2[index+1] - '0'; if(map1[r_name].private2.find(p_name_1) == map1[r_name].private2.end()){ map1[r_name].private2[p_name_1] = level; } else{ int t_level = map1[r_name].private2[p_name_1]; if(t_level < level){ map1[r_name].private2[p_name_1] = level; } } } } } int x3;cin >> x3; for(int i = 0;i < x3;i++){ string user; int k; cin >> user >> k; for(int j = 0;j < k;j++){ string private_name; cin >> private_name; map2[user].push_back(private_name); } } int n;cin >> n; for(int i = 0;i < n;i++){ string user; string now_private; cin >> user >> now_private; if(map2.find(user) == map2.end()){ cout << "false" << endl; continue; } vector<string> user_roles = map2[user]; int index = -1; for(int j = 0;j < now_private.length();j++){ if(now_private[j] == ':'){ index = j; break; } } if(index != -1){ string private_name = ""; for(int j = 0;j < index;j++){ private_name += now_private[j]; } int private_level = now_private[index+1] - '0'; bool flag = false; for(int j = 0;j < user_roles.size();j++){ role role_t = map1[user_roles[j]]; map<string,int> private_2 = role_t.private2; if(private_2.find(private_name) != private_2.end()){ if(private_2.find(private_name)->second >= private_level){ flag = true; break; } } } if(flag){ cout << "true" << endl; } else{ cout << "false" << endl; } } else{ if(private_names.find(now_private) == private_names.end()){ bool flag = false; int ans = -1; for(int j = 0;j < user_roles.size();j++){ role role_t = map1[user_roles[j]]; map<string,int> private_2 = role_t.private2; if(private_2.find(now_private) != private_2.end()){ int level_num = private_2.find(now_private)->second; if(level_num > ans){ ans = level_num; flag = true; } } } if(flag) cout << ans << endl; else cout << "false" << endl; } else{ bool flag = false; for(int j = 0;j < user_roles.size();j++){ role role_t = map1[user_roles[j]]; set<string> private_1 = role_t.private1; if(private_1.find(now_private) != private_1.end()){ flag = true; break; } } if(flag){ cout << "true" << endl; } else{ cout << "false" << endl; } } } } }
c/c++开发分享2016-12-3 ccf 权限查询地址:https://blog.csdn.net/qq_43251559/article/details/107463381
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/c-cdevelopment/598554.html