RT,实在是不知道哪里错了
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#define N 2005
using namespace std;
int n,sz,tag[N],mx[6]={0,255,255,255,255,65535};
string m[N],ad;
char op[N];
bool check(){
int len=ad.length();
for(int i=0; i<len; ++i)
if(!(ad[i]=='.' || ad[i]==':' || (ad[i]>='0' && ad[i]<='9'))) return 0;
// 没有其他字符
int s1=0,s2=0;
for(int i=0; i<len; ++i)
{
if(ad[i]=='.') ++s1;
if(ad[i]==':') ++s2;
if(s1<3 && s2==1) return 0;
}
if(s1!=3 || s2!=1) return 0;
// 点和冒号合法
for(int i=6; i<len; ++i)
{
bool flag=1;
for(int j=0; j<=6; ++j)
if(ad[i-j]<'0' || ad[i-j]>'9') flag=0;
if(flag) return 0;
}
// 爆int
int dlen,num,j=0;
for(int i=1; i<=5; ++i)
{
dlen=0; num=0;
while(j<len && ad[j]>='0' && ad[j]<='9')
{
num=num*10+ad[j]-'0';
++dlen; ++j;
}
++j;
if(dlen==0) return 0;
if(num>0 && (dlen-1 != (int)log10(num))) return 0;
if(num>mx[i]) return 0;
}
// 5个数字
return 1;
}
void moves(int k){
++sz;
m[sz]=ad; tag[sz]=k;
}
int finds(){
for(int i=1; i<=sz; ++i)
if(ad==m[i]) return tag[i];
return 0;
}
int main()
{
// freopen("ans.txt","w",stdout);
scanf("%d",&n);
for(int i=1; i<=n; ++i)
{
ad="";
cin>>op>>ad;
if(op[0]=='S')
{
if(check()==0) cout<<"ERR"<<endl;
else
{
if(finds()) cout<<"FAIL"<<endl;
else {moves(i); cout<<"OK"<<endl;}
}
}
if(op[0]=='C')
{
if(check()==0) cout<<"ERR"<<endl;
else
{
int ans=finds();
if(ans==0) cout<<"FAIL"<<endl;
else cout<<ans<<endl;
}
}
}
return 0;
}