#include <bits/stdc++.h>
#define NOORDER -1
using namespace std;
map<string, int> powers;
map<string, map<string, int>> roles;
map<string, set<string>> users;
void read() {
int p;
cin >> p;
for (int i = 1; i <= p; i++) {
string in;
cin >> in;
auto pos = in.find(':');
if (pos == string::npos) {
powers[in] = -1;
} else {
string name = in.substr(0, pos);
int order = atoi(in.substr(pos + 1).c_str());
powers[name] = order;
}
}
int r;
cin >> r;
for (int i = 0; i < r; i++) {
string role;
cin >> role;
int s;
cin >> s;
for (int j = 1; j <= s; j++) {
string in;
cin >> in;
auto pos = in.find(':');
if (pos == string::npos) {
roles[role][in] = -1;
} else {
string name = in.substr(0, pos);
int order = atoi(in.substr(pos + 1).c_str());
roles[role][name] = max(order, roles[role][name]);
}
}
}
int u;
cin >> u;
for (int i = 1; i <= u; i++) {
string user;
int t;
cin >> user >> t;
for (int j = 1; j <= t; j++) {
string role;
cin >> role;
users[user].insert(role);
}
}
}
int main(){
read();
int q;
cin >> q;
for (int i = 1; i <= q; i++) {
string user;
string power;
cin >> user >> power;
auto pos = power.find(':');
if (!users.count(user)) {
puts("false");
continue ;
}
if (pos == string::npos) {
if (!powers.count(power)) {
puts("false");
continue ;
}
bool find = false;
int odr = -1;
for (auto& r : users[user]) {
if (roles[r].count(power)) {
find = true;
odr = max(odr,roles[r][power]);
}
}
if (find) {
if (powers[power] == -1) puts("true");
else cout <<odr << '\n';
}
else puts("false");
} else {
string name = power.substr(0, pos);
int order = atoi(power.substr(pos + 1).c_str());
if (!powers.count(name)) {
puts("false");
continue ;
}
bool find = false;
int odr = -1;
for (auto& r : users[user]) {
if (roles[r].count(name)) {
if (order <= roles[r][name]) {
find = true;
break ;
}
}
}
if (find) {
puts("true");
}
else puts("false");
}
}
}
CSP 201612-3 权限查询
最新推荐文章于 2024-10-06 14:10:45 发布