Gym100623A Access Control Lists
时间:2021-07-01 10:21:17
帮助过:34人阅读
namespace std;
#define ui unsigned int
ui ip;
map<ui,
int>H[
33];
int main()
{
freopen("access.in",
"r",stdin);
freopen("access.out",
"w",stdout);
ios::sync_with_stdio(false),cin.tie(
0),cout.tie(
0);
int n,q;
cin>>
n;
string s1,s2,s;
for(
int i=
1,x; i<=n; i++
)
{
cin>>s1>>s2>>
s;
for(
int j=
0; s[j]; j++)
if(s[j]<
‘0‘||s[j]>
‘9‘)s[j]=
‘ ‘;
int tot=
0,flag,a[
5];
stringstream ss(s);
while(ss>>a[tot])tot++
;
flag=tot>
4?a[
4]:
32,ip=
0;
for(
int j=
0; j<
4; j++)ip=ip<<
8|
a[j];
if(!
H[flag].count(ip))
{
if(s1[
0]==
‘d‘)H[flag][ip]=-
i;
else H[flag][ip]=
i;
}
}
cin>>
q;
for(
int i=
0,x; i<q; i++
)
{
cin>>
s;
for(
int j=
0; s[j]; j++)
if(s[j]<
‘0‘||s[j]>
‘9‘)s[j]=
‘ ‘;
stringstream ss(s);
ip=
0;
while(ss>>x)ip=ip<<
8|
x;
int res=
10000000;
for(
int j=
32; j>=
0; j--
)
{
if(H[j].count(ip)&&abs(res)>abs(H[j][ip]))res=
H[j][ip];
ip^=((ip>>(
32-j))&
1)<<(
32-
j);
}
cout<<(res>
0?
‘A‘:
‘D‘);
}
return 0;
}
Gym100623A Access Control Lists
标签:分享图片 ret target code stdin 设置 names deny ==