65分求调,谢谢!!!!!
查看原帖
65分求调,谢谢!!!!!
906225
Science_Technologygy楼主2023/11/11 19:48
#include<bits/stdc++.h>
using namespace std;
map<string,int>v;
int n;
string s,x;
bool check(string x){
	int cnt1=0,ok=0,p=0,cnt2=0;
	if(x[0]=='.'||x[0]==':')return false;
	for(int i=0;i<x.size();i++){
		if(x[i]==':')cnt2++;
		else if(x[i]=='.')cnt1++;
		if(cnt2&&cnt1<3)return false;//1类判断 
		if(x[i]>='0'&&x[i]<='9')p=p*10+(x[i]-'0');
		else {
			if(p>255)return false;//2类判断
			p=0; 
		}
		
		if((i==0||x[i-1]=='.')&&x[i]=='0'&&(x[i+1]>='0'&&x[i+1]<='9'))return false;//3类判断 
	}
	if(p>65536)return false;
	if(cnt1!=3||cnt2!=1)return false;
	if(cnt1==3&&cnt2==1)return true;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>s>>x;
		if(s=="Server"){
			if(!check(x))cout<<"ERR"<<endl;
			else{
				if(v[x]==0){
					cout<<"OK"<<endl;
					v[x]=i;
				}
				else cout<<"FAIL"<<endl;
			}
		}
		else{
			if(!check(x))cout<<"ERR"<<endl;
			else{
				if(v[x]==0)cout<<"FAIL"<<endl;
				else cout<<v[x]<<endl;
			}
		}
	}
	return 0;
}
2023/11/11 19:48
加载中...