给爷写吐了,这个模拟真的恶心。
#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();
}
}