求改
查看原帖
求改
490651
zcy942楼主2023/4/22 16:30
#include <iostream>
#include <cstdio>
#include <cmath> 
using namespace std;

inline int read(){
	int ret=0,f=1; char c;
	while((c=getchar())<'0' && c>'9') if(c=='-') f=-1;
	while(c>='0' && c<='9') ret=(ret<<1)+(ret<<3)+(c^48),c=getchar();
	return ret*f;
}

struct tcpip{
	int a,b,c,d,e,sub;
}ser[1010],cli[1010];

int n,si=0,ci=0;

bool num(char c){
	if(c>='0' && c<='9') return 1;
	return 0;
}

bool Check(string ad,bool sorc,int sub){
	
	int a=0,b=0,c=0,d=0,e=0,k=0;
	
	if(ad[k]=='0') return 0;
	while(num(ad[k])) a=(a<<1)+(a<<3)+(ad[k]^48),k++;
	if(ad[k]!='.' || a<0 || a>255) return 0;
	if(ad[++k]=='0') return 0;
	while(num(ad[k])) b=(b<<1)+(b<<3)+(ad[k]^48),k++;
	if(ad[k]!='.' || b<0 || b>255) return 0;
	if(ad[++k]=='0') return 0;
	while(num(ad[k])) c=(c<<1)+(c<<3)+(ad[k]^48),k++;
	if(ad[k]!='.' || c<0 || c>255) return 0;
	if(ad[++k]=='0') return 0;
	while(num(ad[k])) d=(d<<1)+(d<<3)+(ad[k]^48),k++;
	if(ad[k]!=':' || d<0 || d>255) return 0;
	if(ad[++k]=='0') return 0;
	while(num(ad[k])) e=(e<<1)+(e<<3)+(ad[k]^48),k++;
	if(ad[k]!='\0' || e<0 || e>65535) return 0;
	
	if(sorc){
		ser[si].a=a,ser[si].b=b,ser[si].c=c,ser[si].d=d,ser[si].e=e;
		for(int i=0;i<si;i++) if(ser[i].a==ser[si].a && ser[i].b==ser[si].b && ser[i].c==ser[si].c && ser[i].d==ser[si].d && ser[i].e==ser[si].e){
			printf("FAIL\n");
			return 1;
		}
		ser[si].sub=sub+1,si++;
		printf("OK\n");
	}
	else cli[ci].a=a,cli[ci].b=b,cli[ci].c=c,cli[ci].d=d,cli[ci].e=e,ci++;
	return 1;
}



int main(){
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	
	n=read();
	for(int i=0;i<n;i++){
		string op,ad;
		cin>>op>>ad;
		if(op[0]=='S'){
			if(!Check(ad,true,i)) printf("ERR\n");
		}
		else{
			if(!Check(ad,false,i)) printf("ERR\n");
			else{
				int k=ci-1;
				bool find=1;
				for(int j=0;j<si;j++) if(ser[j].a==cli[k].a && ser[j].b==cli[k].b && ser[j].c==cli[k].c && ser[j].d==cli[k].d && ser[j].e==cli[k].e){
					printf("%d\n",ser[j].sub);
					find=0;
				}
				if(find) printf("FAIL\n");
			}
		}
	}
	
	return 0;
}
/*
5
Server 192.168.1.1:8080
Server 192.168.1.1:8080
Client 192.168.1.1:8080
Client 192.168.1.1:80
Client 192.168.1.1:99999
*/
2023/4/22 16:30
加载中...