本蒟蒻写了一个最简单的sscanf,结果拿了个0pts……
代码如下:
#include<bits/stdc++.h>
using namespace std;
unordered_map <string,int> mp;
bool check(string x){
long long a,b,c,d,e;
int num = sscanf(x.c_str(),"%lld.%lld.%lld.%lld:%lld",&a,&b,&c,&d,&e);
if (num != 5)return 0;
if (a < 0 or a > 255)return 0;
if (b < 0 or b > 255)return 0;
if (c < 0 or c > 255)return 0;
if (d < 0 or d > 255)return 0;
if (e < 0 or e > 65535)return 0;
string ans = to_string(a) + '.' + to_string(b) + '.' + to_string(c) + '.';
ans = ans + to_string(d) + ':' + to_string(e);
return ans == x;
}
int main(){
int Q,idx=0;
cin >> Q;
while (Q--){
idx++;
string opt,ip;
cin >> opt >> ip;
if (!check(ip))cout << "ERR\n";
else {
if (opt == "Server"){
if (mp[ip]){
cout << "FAIL\n";
} else {
cout << "OK\n";
mp[ip] = idx;
}
} else {
if (mp[ip]){
cout << mp[ip];
} else {
cout << "FAIL\n";
}
}
}
}
return 0;
}