#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10;
long long a[N],b[N],c[N],d[N],e[N],n,xx,m[N],cnt=0,jame;
char f[N],g[N],h[N],l[N],ff,gg,hh,ll;
bool p;
string op,s,t,t1,t2,t3,t4,t5;
bool one(long long x){
int xxx=x;
x=m[x];
if(x==0){
return 0;
}
if(a[x]==a[xx] && f[x]==f[xx] && b[x]==b[xx] && g[x]==g[xx] && c[x]==c[xx] && h[x]==h[xx] && d[x]==d[xx] && l[x]==l[xx] && e[x]==e[xx]){
return 1;
}
x=xxx;
return one(x-1);
}
bool two(long long x){
if(a[x]<0 || a[x]>255){
return 1;
}
if(b[x]<0 || b[x]>255){
return 1;
}
if(c[x]<0 || c[x]>255){
return 1;
}
if(d[x]<0 || d[x]>255){
return 1;
}
if(e[x]<0 || e[x]>65535){
return 1;
}
if(f[x]!='.'){
return 1;
}
if(g[x]!='.'){
return 1;
}
if(h[x]!='.'){
return 1;
}
if(l[x]!=':'){
return 1;
}
return 0;
}
long long three(long long x,long long y){
int yy=y;
y=m[y];
if(y==0){
return 0;
}
if(a[x]==a[y] && f[x]==f[y] && b[x]==b[y] && g[x]==g[y] && c[x]==c[y] && h[x]==h[y] && d[x]==d[y] && l[x]==l[y] && e[x]==e[y]){
return y;
}
y=yy;
return three(x,y+1);
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>op;
cin>>s;
jame=0;
t="";
p=0;
for(int j=0;j<=s.size();j++){
if(s[j]>='0' && s[j]<='9'){
t=t+s[j];
}
else{
if(t[0]=='0' && t.size()!=1){
cout<<"ERR"<<endl;
p=1;
break;
}
if(t.size()>0){
jame++;
}
if(jame==1){
t1=t;
ff=s[j];
}
if(jame==2){
t2=t;
gg=s[j];
}
if(jame==3){
t3=t;
hh=s[j];
}
if(jame==4){
t4=t;
ll=s[j];
}
if(jame==5){
t5=t;
}
t="";
}
}
if(p==1){
continue;
}
if(jame!=5){
cout<<"ERR"<<endl;
continue;
}
for(int j=0;j<t1.size();j++){
a[i]=a[i]*10+(t1[j]-'0');
}
for(int j=0;j<t2.size();j++){
b[i]=b[i]*10+(t2[j]-'0');
}
for(int j=0;j<t3.size();j++){
c[i]=c[i]*10+(t3[j]-'0');
}
for(int j=0;j<t4.size();j++){
d[i]=d[i]*10+(t4[j]-'0');
}
for(int j=0;j<t5.size();j++){
e[i]=e[i]*10+(t5[j]-'0');
}
f[i]=ff;
g[i]=gg;
h[i]=hh;
l[i]=ll;
xx=i;
if(op[0]=='S'){
m[++cnt]=i;
if(two(i)){
cout<<"ERR"<<endl;
}
else if(one(cnt-1)){
cout<<"FAIL"<<endl;
}
else{
cout<<"OK"<<endl;
}
}
else{
if(two(i)){
cout<<"ERR"<<endl;
}
else{
if(three(i,1)==0){
cout<<"FAIL"<<endl;
}
else{
cout<<three(i,1)<<endl;
}
}
}
}
}
求求了,我错在哪里了