交了十几遍了,咋就才65分呢
查看原帖
交了十几遍了,咋就才65分呢
406170
Jason_yinkai楼主2022/10/16 09:13
#include<bits/stdc++.h>
using namespace std;
int n,m;
string server[10000000];
bool check(string x){//判断语法错误 
	long long num[100],tmp = 1;
	memset(num,0,sizeof(num));
	if(x[0] == '0' and x[1] != '.' and x[1] != ':')return false;//前导零在第一位 
	for(int i = 0;i < x.length();i++){
		if(x[i] == ':' or x[i] == '.'){
			tmp++;//下一个数 
			if(tmp <= 4 and x[i] == ':')return false;
			else if(tmp == 5 and x[i] == '.')return false;//判断'.'或':' 
			if(x[i + 1] == '0' and x[i + 2] != '.' and x[i + 2] != ':')return false;//判断前导零 
			continue;
		}
		num[tmp] = num[tmp] * 10 + (x[i] - '0');
	}
	if(tmp != 5)return false;//没有5个数 
	if(num[1] > 255 or num[2] > 255 or num[3] > 255 or num[4] > 255 or num[5] > 65535)return false;
	return true;
}
bool server_c(string x){
	for(int i = 1;i <= m;i++){
		if(server[i] == x)return false;//与之前的地址串有重复 
	}
	return true;//没有重复 
}
int client_c(string x){
	for(int i = 1;i <= n;i++){
		if(server[i] == x)return i;//找到了 
	}
	return -1;//没找到 
}
int main(){
	cin>>n;
	for(int i = 1;i <= n;i++){
		string s,op;
		cin>>s;
		m++;
		if(s == "Server"){
			cin>>op;
			bool a = check(op)/*语法错误*/,b = server_c(op)/*与之前的地址有重复*/;
			if(a == 1 and b == 1){
				cout<<"OK"<<endl;server[m] = op;//吧合法的地址串存下来 
			}
			else if(a == 1 and b == 0)cout<<"FAIL"<<endl;
			else cout<<"ERR"<<endl;
		}
		else{
			cin>>op;
			bool a = check(op);/*语法错误*/
			int b = client_c(op);/*匹配的Server的编号*/
			if(a == 1 and b != -1)cout<<b<<endl;/*没有错误且找到了*/ 
			else if(a == 1 and b == -1)cout<<"FAIL"<<endl;/*没有错误但没找到*/ 
			else cout<<"ERR"<<endl;/*语法错误*/ 
		}
	}
} 

测试点

2022/10/16 09:13
加载中...