#include<bits/stdc++.h>
using namespace std;
int n,m;
string server[10000000];
bool check(string x){
long long num[100],tmp = 1;
memset(num,0,sizeof(num));
if(x[0] == '0' and x[1] != '.' and x[1] != ':')return false;
for(int i = 0;i < x.length();i++){
if(x[i] == ':' or x[i] == '.'){
tmp++;
if(tmp <= 4 and x[i] == ':')return false;
else if(tmp == 5 and x[i] == '.')return false;
if(x[i + 1] == '0' and x[i + 2] != '.' and x[i + 2] != ':')return false;
continue;
}
num[tmp] = num[tmp] * 10 + (x[i] - '0');
}
if(tmp != 5)return false;
if(num[1] > 255 or num[2] > 255 or num[3] > 255 or num[4] > 255 or num[5] > 65535)return false;
return true;
}
bool server_c(string x){
for(int i = 1;i <= m;i++){
if(server[i] == x)return false;
}
return true;
}
int client_c(string x){
for(int i = 1;i <= n;i++){
if(server[i] == x)return i;
}
return -1;
}
int main(){
cin>>n;
for(int i = 1;i <= n;i++){
string s,op;
cin>>s;
m++;
if(s == "Server"){
cin>>op;
bool a = check(op),b = server_c(op);
if(a == 1 and b == 1){
cout<<"OK"<<endl;server[m] = op;
}
else if(a == 1 and b == 0)cout<<"FAIL"<<endl;
else cout<<"ERR"<<endl;
}
else{
cin>>op;
bool a = check(op);
int b = client_c(op);
if(a == 1 and b != -1)cout<<b<<endl;
else if(a == 1 and b == -1)cout<<"FAIL"<<endl;
else cout<<"ERR"<<endl;
}
}
}
测试点