#include<bits/stdc++.h>
using namespace std;
int n,cnt;
struct serve{
int id;
string ad;
} a[1005];
bool law(string s){
int dian=0,maohao=0,cnt;
for(int i=0;i<s.size();i++){
if(s[i]=='.'){
dian++;
if(s[i+1]<'0'||s[i+1]>'9'||i==0) return false;
} //注意开头为字符的错误!!!
else if(s[i]==':'){
maohao++;
if(s[i+1]<'0'||s[i+1]>'9'||i==0) return false;
}
else if(s[i]<'0'||s[i]>'9') return false;
else{
if(s[i]=='0'&&s[i+1]>='0'&&s[i+1]<='9') return false;
cnt++;//十年OI一场空,不开longlong见祖宗!!!
long long temp=s[i]-'0';//Client 8.25.3.17:4294967297
while(s[i+1]>='0'&&s[i+1]<='9'){
i++;
temp=temp*10+s[i]-'0';
}
//cout<<cnt<<' '<<temp<<endl;
if(cnt<=4&&temp>255) return false;
else if(temp>65535) return false;
}
}
if(dian!=3||maohao!=1) return false;
return true;
}
int main(){
//freopen("net.in","r",stdin);
//freopen("net.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++){
string type;
string addr;
cin>>type>>addr;
if(!law(addr)) {
cout<<"ERR"<<endl;
continue;
}
else{
if(type=="Server"){
bool can=true;
for(int j=1;j<=cnt;j++){
if(a[j].ad==addr){
can=false;
break;
}
}
if(!can) cout<<"FAIL"<<endl;
else{
cnt++;
a[cnt].ad=addr;
a[cnt].id=i;
cout<<"OK"<<endl;
}
}
else{
bool tcan=false;
int tpos;
for(int j=1;j<=cnt;j++){
if(a[j].ad==addr){
tpos=a[j].id;
tcan=true;
break;
}
}
if(!tcan) cout<<"FAIL"<<endl;
else cout<<tpos<<endl;
}
}
}
return 0;
}
代码比较繁琐,纯模拟,救救孩子吧 (plus能不能私信我)