#include <bits/stdc++.h>
using namespace std;
inline int read()
{
int ww = 0,ee = 1;
char ch = getchar();
while (ch < '0' || ch > '9')
{
if (ch == '-')
{
ee = -1;
}
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
ww = ww * 10 + ch - '0';
ch = getchar();
}
return ww * ee;
}
void file()
{
freopen(".in","r",stdin);
freopen(".out","w",stdout);
}
map <string,int> mp;
int n;
int a[10];
char is[5] = {'.','.','.',':'};
bool check(string s)
{
int len = s.size();
memset(a,-1,sizeof(a));
int tot = 1;
int suma = 0,sumb = 0;
for (int i = 0;i < len;i++)
{
if (isdigit(s[i]))
{
if (a[tot] == -1) a[tot] = 0;
a[tot] = a[tot] * 10 + s[i] - '0';
}
else
{
if (s[i] == '.')
{
suma++;
}
else
{
sumb++;
}
if (s[i] != is[tot-1])
{
return 0;
}
tot++;
if (s[i+1] == '0' && isdigit(s[i+2]))
{
return 0;
}
}
}
for (int i = 1;i <= 5;i++)
{
if (a[i] == -1)
{
return 0;
}
}
if (suma != 3 || sumb != 1)
{
return 0;
}
if (!(a[1] >= 0 && a[1] <= 255 && a[2] >= 0 && a[2] <= 255 && a[3] >= 0 && a[3] <= 255 && a[4] >= 0 && a[4] <= 255 && a[5] >= 0 && a[5] <= 65535))
{
// cout << a[1] << ' ' << a[2] << ' ' << a[3] << ' ' << a[4] << ' ' << a[5] << endl;
return 0;
}
return 1;
}
int main()
{
n = read();
for (int i = 1;i <= n;i++)
{
string op,s;
cin >> op >> s;
if (op[0] == 'S')
{
if (!check(s))
{
printf("ERR\n");
continue;
}
if (mp[s])
{
printf("FAIL\n");
continue;
}
mp[s] = i;
printf("OK\n");
}
else
{
if (!check(s))
{
printf("ERR\n");
continue;
}
if (!mp[s])
{
printf("FAIL\n");
continue;
}
printf("%d\n",mp[s]);
}
}
return 0;
}
全WA。。。