4088. 网络连接
作者:
jy9
,
2024-08-26 13:40:32
,
所有人可见
,
阅读 2
#include <iostream>
#include <vector>
#include <unordered_map>
#include <sstream>
using namespace std;
unordered_map<string, int> mp;
bool check(string str){
vector<int> a(5, -1);
sscanf(str.c_str(), "%d.%d.%d.%d:%d", &a[0], &a[1], &a[2], &a[3], &a[4]);
for (int i = 0; i < 4; i ++ )
if(a[i] > 255 || a[i] < 0)return false;
if(a[4] > 65535 || a[4] < 0)return false;
char b[110];
sprintf(b, "%d.%d.%d.%d:%d", a[0], a[1], a[2], a[3], a[4]);
return str == b;
}
int main(){
int n;
cin >> n;
string op, ad;
for (int i = 1; i <= n; i ++ ){
cin >> op >> ad;
if(op == "Server"){
if(!check(ad)){
cout << "ERR" << endl;
continue;
}
else if(mp[ad]){
cout << "FAIL" << endl;
continue;
}
mp[ad] = i;
cout << "OK" << endl;
}
else if (op == "Client"){
if(!check(ad)){
cout << "ERR" << endl;
continue;
}
else if(!mp[ad]){
cout << "FAIL" << endl;
continue;
}
cout << mp[ad] << endl;
}
}
return 0;
}