题解
2024-09-28 13:25:30
发布于:北京
26阅读
0回复
0点赞
#include <iostream>
#include <memory.h>
#include <cstdio>
#include <vector>
#include <set>
using namespace std;
struct node{
int a[6] = {0};
};
vector <node> v;
int a[100005];
char b[100005];
int main(){
int t, __ct = 0;
cin >> t;
if(0){error: cout << "ERR\n";}
if(0){fail: cout << "FAIL\n";}
while(t--){
__ct++;
memset(a, 0, 1000);
memset(b, 0, 1000);
string tmp, str;
cin >> tmp >> str;
int ct = 1, i;
if(!isdigit(str[0])) goto error;
for(i = 0; str[i] != '\0'; i++){
if(!isdigit(str[i])){
if(ct <= 4 && a[ct] > 255 || a[ct] > 65535 || i && !isdigit(str[i - 1])) goto error;
b[ct++] = str[i];
}
else{
if(a[ct] == 0 && str[i] == '0' && isdigit(str[i + 1])) goto error;
a[ct] = a[ct] * 10 + str[i] - '0';
if(ct <= 4 && a[ct] > 255 || a[ct] > 65535) goto error;
}
}
if(ct != 5 || a[5] > 65535 || !isdigit(str[i - 1])) goto error;
for(int i = 1; i <= 3; i++){
if(b[i] != '.') goto error;
}
if(b[4] != ':') goto error;
if(tmp == "Server"){
for(auto it:v){
bool flag = 1;
for(int i = 1; i <= 5; i++) if(it.a[i] != a[i]) flag = 0;
if(flag) goto fail;
}
cout << "OK\n";
node tmp;
for(int i = 1; i <= 5; i++) tmp.a[i] = a[i];
tmp.a[0] = __ct;
v.push_back(tmp);
}else{
int idx = -1;
for(int i = 0; i < v.size(); i++){
bool flag = 1;
for(int j = 1; j <= 5; j++){
if(v[i].a[j] != a[j]) flag = 0;
}
if(flag){
idx = v[i].a[0];
break;
}
}
if(idx == -1) goto fail;
cout << idx << endl;
}
}
return 0;
}
全部评论 3
司马
2024-09-28 来自 广东
0神金
2024-09-28 来自 广东
0?
2024-09-28 来自 广东
0
有帮助,赞一个