题解
2024-10-19 15:04:39
发布于:广东
78阅读
0回复
0点赞
司马Zzz超我题解
CSPJ都这么难的吗
超绝大模拟
有几个坑点注意一下:
1.不允许前导0不代表不允许地址的某一个地方为0,比如说 192.168.0.255:80
中第三个区域一开始是0,但是它是合法的
2.要判断一开始是不是数字,比如 .123.213.231:14514
不是合法的,很难找到这个问题
来给你们造个最全的数据
8
Client 0.0.0.0:0
Client 255.255.255.255:65535
Client .0.0.0:0
Client 0.0.0.0:
Client 0.0.0.0:0:
Client 2147483649.2147483649.2147483649.2147483649:2147483649
Client 0.0.00.0:0
Client 0.0..0:0
FAIL
FAIL
ERR
ERR
ERR
ERR
ERR
ERR
只要判断好错误,剩下的就很简单了
用一个vector储存记录,循环判断重复
#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;
}
全部评论 1
管哥你的样例我都对,但还是不对
2024-10-20 来自 广东
0
有帮助,赞一个