#include<bits/stdc++.h>
using namespace std;
bool tmp(string s)
{
if(s!="0"&&s[0]=='0') return false;
return true;
}
bool check(string s)
{
int point=0;
int moup=0;
if(s[0]=='.') return false;
int mou=0;
for(int i=0;i<int(s.size());i++)
{
if(s[i]=='.'&&s[i+1]=='.') return false;
if(s[i]=='.') point++;
if(s[i]==':') mou++;
if(s[i]==':'&&point==3) moup++;
}
if(point!=3&&moup!=1&&mou!=1) return false;
int a=0,b=0,c=0,d=0,e=0;
int i=0;
string s1,s2,s3,s4,s5;
while(s[i]!='.')
{
a=a*10+s[i]-'0';
s1+=s[i];
i++;
}
i++;
while(s[i]!='.')
{
b=b*10+s[i]-'0';
s2+=s[i];
i++;
}
i++;
while(s[i]!='.')
{
c=c*10+s[i]-'0';
s3+=s[i];
i++;
}
i++;
while(s[i]!=':')
{
d=d*10+s[i]-'0';
s4+=s[i];
i++;
}
i++;
while(i<int(s.size()))
{
e=e*10+s[i]-'0';
s5+=s[i];
i++;
}
//cout<<s5<<endl;
//cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl;
if(a<0||a>255||b<0||b>255||c<0||c>255||d<0||d>255||e<0||e>65535||!tmp(s1)||!tmp(s2)||!tmp(s3)||!tmp(s4)||!tmp(s5)) return false;
return true;
}
int main()
{
//freopen("network.in","r",stdin);
//freopen("network.out","w",stdout);
map<string,int> mp;
int t;
cin>>t;
for(int i=1;i<=t;i++)
{
string s;
cin>>s;
string s1;
cin>>s1;
if(!check(s1)) cout<<"ERR"<<endl;
else
{
if(s=="Server")
{
if(mp[s1]!=0) cout<<"FAIL"<<endl;
else
{
mp[s1]=i;
cout<<"OK"<<endl;
}
}
else
{
if(mp[s1]==0) cout<<"FAIL"<<endl;
else cout<<mp[s1]<<endl;
}
}
}
return 0;
}
cmp算前导零
check 判合法
RE