You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.7 KiB

2 years ago
#include <bits/stdc++.h>
using namespace std;
int n;
// sscanf和sprintf详解
// https://blog.csdn.net/qq_40563761/article/details/107087811
/*
sscanfsprintf
sscanf(str,"%d",&n) str"%d"n
sprintf(str,"%d",n)n"%d"str
*/
bool check(string s) {
int a, b, c, d, port;
//字符串格式化提取+判断转换成功个数
if (sscanf(s.c_str(), "%d.%d.%d.%d:%d", &a, &b, &c, &d, &port) != 5) return false;
//需符合IP地址规则
if (a < 0 || a > 255 || b < 0 || b > 255 || c < 0 || c > 255 || d < 0 || d > 255 || port < 0 || port > 65535)
return false;
/*
:
179.90.115.156:54168:
OKOK!
*/
// if ((string)ss != s) {
// cout << "ss=" << (string)ss << endl;
// cout << s << endl;
// }
char ss[25]; // 3*4+3+5=20
sprintf(ss, "%d.%d.%d.%d:%d", a, b, c, d, port);
return (string)ss == s;
}
map<string, int> _map;
string op, ip;
int main() {
//文件输入
freopen("P7911_13.in", "r", stdin);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> op >> ip;
if (!check(ip)) {
cout << "ERR" << endl;
continue;
}
if (op == "Server") {
if (_map[ip])
puts("FAIL");
else
_map[ip] = i, puts("OK");
} else {
if (_map[ip] == 0)
puts("FAIL");
else
printf("%d\n", _map[ip]);
}
}
return 0;
}