AC

robin88  •  2个月前


include

include

include

include

include <stdlib.h>

using namespace std; / run this program using the console pauser or add your own getch, system("pause") or input loop / bool is_valid_section(string subStr1, int max){

if(subStr1 == "")  return false;
if(subStr1.length()>=6) return false;
int subNum = atoi(subStr1.c_str());
if(subNum>max){
	return false;
}
if(subStr1.length()>1 && subStr1[0]=='0') return false;

return true;

}

bool form_true_or_false(string ad){

int n=0,q=0,w=0,x=0,y=0;
int form1[3]={0};
int form2=0;
int a[5]={0}; 

vector<string> subStrs;
string subStr = "";
for(int i=0;i<ad.length();i++){
	if(ad[i]=='.') {
	form1[x]=i;
	x++;	
	}
	if(ad[i]==':'){
		form2=i;
		y++;
	}
}
if(x!=3 || y!=1){
	return false;
}
for(int q=0;q<3;q++){
	if(form1[q]>form2){
		return false;
	}
}

for(int i=0;i<=ad.length();i++){		
	if((ad[i] != '.' && ad[i] != ':') && ad[i]!='\0') {
		subStr.push_back(ad[i]);
	}
	else{
		subStrs.push_back(subStr);
		subStr = "";
	}
}

for(int j=0;j<subStrs.size();j++){

// int max = (j !=4):255,65535;

	int max = 0;
	if(j !=4)
	{
		max = 255;
	}
	else{
		max = 65535;
	}
	
	if (!is_valid_section(subStrs[j], max)){
		return false;
	}
}
return true;	

} int main(int argc, char** argv) {

int n,h,a=0,b=0;
string op,ad;
cin>>n;
vector<string> k(n);
vector<int> id(n);
for(int i=0;i<n;i++){
	cin>>op;
	cin>>ad;	
	if(!(form_true_or_false(ad))){
		cout<<"ERR"<<endl;
		continue;
	}
	bool m=false;
	for(int j=0;j<a;j++){
		if(ad==k[j]){
			 h=j;
			 m=true;
			 continue;
		}
	}

	if(m){  //在servers里找到 
		
		if(op=="Server"){
			cout<<"FAIL"<<endl;
		}
		else{
			cout<<id[h]<<endl;
		} 
	}
	else{
		if(op=="Server"){		
			k[a]=ad;
			id[a]=i+1;
			a++;
			cout<<"OK"<<endl;
		}
		else{
			cout<<"FAIL"<<endl;
		} 
	} 
}
return 0;

}


评论:

请先登录,才能进行评论