#include<bits/stdc++.h>
using namespace std;
int ans,s[1005][6];
long long c,e,d,m,q[6],i;
bool w;
void Client(int a,int b,int c,int d,int e,int n){
if(a>255||b>255||c>255||d>255||e>65535){
cout<<"ERR"<<endl;
return;
}
for(i=1;i<=ans;i++){
if(s[i][1]==a&&s[i][2]==b&&s[i][3]==c&&s[i][4]==d&&s[i][5]==e){
cout<<s[i][0]<<endl;
return;
}
}
cout<<"FAIL"<<endl;
return;
}
void Server(int a,int b,int c,int d,int e,int n){
if(a>255||b>255||c>255||d>255||e>65535){
cout<<"ERR"<<endl;
return;
}
for(i=1;i<=ans;i++){
if(s[i][1]==a&&s[i][2]==b&&s[i][3]==c&&s[i][4]==d&&s[i][5]==e){
cout<<"FAIL"<<endl;
return;
}
}
ans++;
s[ans][1]=a;
s[ans][2]=b;
s[ans][3]=c;
s[ans][4]=d;
s[ans][5]=e;
s[ans][0]=n;
cout<<"OK"<<endl;
return;
}
void check(int n){
string a,b;
cin>>a>>b;
c=b.size()-1;
for(e=1;e<=5;e++){
q[e]=0;
}
e=1;
d=0;
m=0;
w=0;
for(i=0;i<=c;i++){
if(b[i]>='0'&&b[i]<='9'){
w=1;
q[e]=q[e]*10+b[i]-'0';
if(q[e]==0&&b[i+1]!='.'&&b[i+1]!=':'){
cout<<"ERR"<<endl;
return;
}
}
else{
if(b[i]=='.'){
d++;
}
else{
m++;
}
w=0;
e++;
}
}
if(d!=3||m!=1){
cout<<"ERR"<<endl;
return;
}
if(a=="Server"){
Server(q[1],q[2],q[3],q[4],q[5],n);
}
else{
Client(q[1],q[2],q[3],q[4],q[5],n);
}
return;
}
int main(){
int n;
cin>>n;
for(int o=1;o<=n;o++){
check(o);
}
}
ans:当前已有多少台服务机成功联网
s存储每台服务机的IP:a,b,c,d,e
两个以单词命名的函数为连接配对
Check为读入+特判+预处理
c,e,d,m,q,i,w为临时变量
s[][0]:编号
s[][1]:a
s[][2]:b
s[][3]:c
s[][4]:d
s[][5]:e