- C++
AK
- @ 2025-10-24 21:38:06
在前导零判定上借鉴了部分题解思路
#include <iostream>
#include <algorithm>
#include <map>
#include <cstring>
#include <sstream>
#include <cstdio>
using namespace std;
int n;
map <string,int> server;
bool check_for(string ss){
int len = ss.size();
string gs = "";
for(int i = 0;i < len;i++) {
if(ss[i] == '.' || ss[i] == ':'){
gs += ss[i];
}
}
if(gs == "...:"){
return 1;
}
else{
return 0;
}
}
long long int a,b,c,d,e;
int main(){
string op,ad;
//ios::sync_with_stdio(false);
//cin.tie(0), cout.tie(0);
cin >> n;
for(int i = 0;i < n;i ++){
a = 0;b = 0;c = 0;d = 0;e = 0;
cin >> op >> ad;
if(check_for(ad)){
sscanf(ad.c_str(),"%lld.%lld.%lld.%lld:%lld",&a,&b,&c,&d,&e);
stringstream sss;
sss << a << '.' << b << '.' << c << '.' << d << ':' << e;
string ssss = sss.str();
if(ssss != ad){
cout << "ERR\n";
}else if(a < 256 && b < 256 && c < 256 && d < 256 && e < 65536 && op == "Server"){
if(server.count(ad) < 1 || server.empty()){
server.insert(pair<string,int>(ad,i+1));
cout << "OK\n";
}else{
cout << "FAIL\n";
continue;
}
}else if(a < 256 && b < 256 && c < 256 && d < 256 && e < 65536 && op == "Client"){
if(server.find(ad) != server.end()){
cout << server[ad] << "\n";
}else{
cout << "FAIL\n";
}
}else{
cout << "ERR\n";
continue;
}
}else{
cout << "ERR\n";
continue;
}
}
return 0;
}
1 comments
-
C24yechenxi LV 1 @ 2025-10-24 21:38:47stringstream是真难绷🤣 1
- 1