前导零已解决。
#include<bits/stdc++.h>
#define ll long long
#define ts to_string
using namespace std;
map<string, int> m;
int cnt;
int main(){
int t;
cin>>t;
for(cnt=1;cnt<=t;cnt++){
string op;
cin>>op;
if(op=="Server"){
string s;
cin>>s;
ll a, b, c, d, e;
ll f=sscanf(s.c_str(), "%lld.%lld.%lld.%lld:%lld", &a, &b, &c, &d, &e);
string ss;
ss=ts(a)+'.'+ts(b)+'.'+ts(c)+'.'+ts(d)+':'+ts(e);
if(ss!=s) goto err;
if(f!=5) goto err;
if(a>255 || a<0) goto err;
if(b>255 || b<0) goto err;
if(c>255 || c<0) goto err;
if(d>255 || d<0) goto err;
if(e>65535 || e<0) goto err;
if(m[s]) goto fail;
m[s]=cnt;
cout<<"OK"<<endl;
continue;
}
else if(op=="Client"){
string s;
cin>>s;
ll a, b, c, d, e;
ll f=sscanf(s.c_str(), "%lld.%lld.%lld.%lld:%lld", &a, &b, &c, &d, &e);
if(f!=5) goto err;
if(a>255 || a<0) goto err;
if(b>255 || b<0) goto err;
if(c>255 || c<0) goto err;
if(d>255 || d<0) goto err;
if(e>65535 || e<0) goto err;
if(!m[s]) goto fail;
cout<<m[s]<<endl;
continue;
}
err:
cout<<"ERR"<<endl;
continue;
fail:
cout<<"FAIL"<<endl;
continue;
}
return 0;
}