-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path201612-3.cpp
91 lines (91 loc) · 1.93 KB
/
201612-3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <bits/stdc++.h>
using namespace std;
map<string,int> pri;
map<string,map<string,int> > rol;
map<string,map<string,int> > usr;
void find(string u,string x,int lev)
{
if(usr.count(u)>0&&usr[u].count(x)>0)
{
if(lev==-1)
{
if(usr[u][x]>-1) cout<<usr[u][x]<<endl;
else cout<<"true\n";
}
else
{
if(usr[u][x]>=lev) cout<<"true\n";
else cout<<"false\n";
}
}
else cout<<"false\n";
}
int main()
{
int n;
cin>>n;//p
while(n--)
{
string x;
cin>>x;
size_t pos=x.find(":");
if(pos==string::npos) pri[x]=-1;
else
{
int lev=x[pos+1]-'0';
x=x.substr(0,pos);
pri[x]=max(pri[x],lev);
}
}
cin>>n;//r
while(n--)
{
string role;
int k;
cin>>role>>k;
while(k--)
{
string x;
cin>>x;
size_t pos=x.find(":");
if(pos==string::npos) rol[role][x]=-1;
else
{
int lev=x[pos + 1]-'0';
x=x.substr(0,pos);
rol[role][x]=max(rol[role][x],lev);
}
}
}
cin>>n;//u
while(n--)
{
string u;
int k;
cin>>u>>k;
while(k--)
{
string x;
cin>>x;
map<string,int>::iterator it=rol[x].begin();
while(it!=rol[x].end())
{
if(usr[u].count(it->first)>0)
usr[u][it->first]=max(usr[u][it->first],it->second);
else
usr[u][it->first]=it->second;
++it;
}
}
}
cin>>n;//q
while(n--)
{
string u,x;
cin>>u>>x;
size_t pos=x.find(":");
if(pos==string::npos) find(u,x,-1);
else find(u,x.substr(0,pos),x[pos+1]-'0');
}
return 0;
}