#include <iostream>
#include <cstring>
#include <map>
using namespace std;
map<pair<unsigned long long,long long>,int> vis_server;
unsigned long long hash1(string s){
unsigned long long p=0;
for(int i=0;i<s.length();i++)
p=p*131+int(s[i]);
return p;
}
int mod=1e9+7;
long long hash2(string s){
long long res=0;
for(int i=0;i<s.length();i++){
res=res*131+int(s[i]);
res=res%mod;
}
return res;
}
bool check_it(string s){
if(s[0]<'0' or s[0]>'9') return false;
int cnt_dot=0,cnt_mark=0;
bool flag=false;
for(int i=1;i<int(s.length());i++){
if(s[i]=='.' and !flag) cnt_dot++;
else if(s[i]==':'){
cnt_mark++;
flag=true;
}
else if(s[i]=='.' and flag) return false;
else if(s[i]<'0' or s[i]>'9') return false;
}
if(cnt_dot!=3 or cnt_mark!=1) return false;
return true;
}
int cnt=0;
int check_num(string s){
while((s[cnt]<'0' or s[cnt]>'9') and cnt<s.length()) cnt++;
if(s[cnt]=='0' and cnt+1<int(s.length()) and s[cnt+1]>='0' and s[cnt+1]<='9') return -1;
long long num=0;
while(s[cnt]>='0' and s[cnt]<='9' and cnt<int(s.length())){
num=(num<<1)+(num<<3)+s[cnt]-'0';
if(num>65535) return -1;
cnt++;
}
return num;
}
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
string op,ad;
cin>>op>>ad;
cnt=0;
if(!check_it(ad)){
cout<<"ERR"<<endl;
continue;
}
int num1=check_num(ad),num2=check_num(ad),num3=check_num(ad),num4=check_num(ad),num5=check_num(ad);
if(num1<0 or num2<0 or num3<0 or num4<0 or num5<0){
cout<<"ERR"<<endl;
continue;
}
if(num1>255 or num2>255 or num3>255 or num4>255 or num5>65535){
cout<<"ERR"<<endl;
continue;
}
unsigned long long h1=hash1(ad);
long long h2=hash2(ad);
pair<unsigned long long,long long> p1=make_pair(h1,h2);
if(op=="Server"){
if(vis_server[p1]){
cout<<"FAIL"<<endl;
continue;
}
vis_server[p1]=i;
cout<<"OK"<<endl;
}
if(op=="Client"){
if(!vis_server[p1]){
cout<<"FAIL"<<endl;
continue;
}
cout<<vis_server[p1]<<endl;
}
}
return 0;
}
我吐了啊,调了一整天都调不对 求各位大佬指教