样例没过,大佬求调!
查看原帖
样例没过,大佬求调!
471767
Ar_cher楼主2023/2/25 15:18
#include<bits/stdc++.h>
using namespace std;
const int N=1005;
int n,cnzi;
string op,ad; 
int ERR=0;
int a[N],b[N],c[N],d[N],e[N];
int w[N];
bool hefa(int i){//数值是否合法 
	if(!(a[i]>=0 and a[i]<=255)) return false;
	if(!(b[i]>=0 and b[i]<=255)) return false;
	if(!(c[i]>=0 and c[i]<=255)) return false;
	if(!(d[i]>=0 and d[i]<=255)) return false;
	if(!(e[i]>=0 and e[i]<=65535)) return false;
	return true;
}
bool chong(int i,int j){//判断服务器重复问题 
	if(!(a[i]==a[j])) return false;
	if(!(b[i]==b[j])) return false;
	if(!(c[i]==c[j])) return false;
	if(!(d[i]==d[j])) return false;
	if(!(e[i]==e[j])) return false;
	return true;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>op>>ad;
		ERR=0;
		int dian=0,mao=0;
		int len=ad.size();
		int f;
		for(int j=0;j<ad.size();j++){
			if(ad[j]=='.') dian++;
			if(ad[j]==':') mao++;
		}
		if(dian==3 and mao==1){
			ad+=".";
			if(op=="Server") f=1;
			else f=2;
			string zifu="";//.与:之间的字符存储器
			int cnt=0;
			for(int j=0;j<ad.size();j++){
				if(ad[j]='.' or ad[j]==':'){
					if(cnt==0 and (ad[j]!='.')) ERR=1;
					if(cnt==1 and (ad[j]!='.')) ERR=1;
					if(cnt==2 and (ad[j]!='.')) ERR=1;
					if(cnt==3 and (ad[j]!=':')) ERR=1;
					if(zifu=="") ERR=1;//非空串
					if(zifu[0]=='0' and zifu.size()!=1) ERR=1;//前导0;
					int sum=0;//相当与数字型的zifu[] 
					for(int k=0;k<zifu.size();k++) cnzi=cnzi*10+zifu[k]-'0';
					cnt++;
					if(sum==1) a[i]=cnzi;
					else if(sum==2) b[i]=cnzi;
					else if(sum==3) c[i]=cnzi;
					else if(sum==4) d[i]=cnzi;
					else if(sum==5) e[i]=cnzi;
					zifu="";
				}
				else zifu+=ad[j];
			}
		}
		if(!hefa(i)) ERR=1;//合法或不合法 
		else ERR=1;	
		if(ERR==1){
			cout<<"ERR"<<endl;
			continue;
		}
		if(f==1){
			int ok=1;
			for(int j=1;j<=i-1;j++){
				if(w[j]==1 and chong(i,j)){
					ok=0;
					break;
				}
			}
			if(ok==0) cout<<"FAIL"<<endl;
			else{
				cout<<"OK"<<endl;
				w[i]=1;
			}
		}
		else if(f==2){
			int ok=0,id;
			for(int j=1;j<=i-1;j++){
				if(w[j]==1 and chong(i,j)){
					ok=1;
					id=j;
					break;
				}
			} 
			if(ok==0) cout<<"FAIL"<<endl;
			else cout<<id<<endl;
		}
	}
	return 0;
}
2023/2/25 15:18
加载中...