80pts 求调 RE
查看原帖
80pts 求调 RE
224546
cym_yyds楼主2021/11/22 22:24
#include<bits/stdc++.h>
using namespace std;
int n;
const int N=1010;
string op,ad; 
map<string, int> now;
bool check(string s)
{
	long long a[6]={0};
	int idx=1;
	int len=s.size();
	int cntpoint=0,cntmaohao=0;
	bool first=true;
	s[len]='a';
	if(!(s[0]>='0'&&s[0]<='9')){cout<<s[0]<<' ';return false;} 
	for(int i=0;i<len;i++)
	{
		if(!(s[i]>='0'&&s[i]<='9')&&s[i]!='.'&&s[i]!=':')return false;
		if(s[i]=='-')return false;
		if(s[i]>='0'&&s[i]<='9'){
			if(s[i]=='0'&&first==true){
				if(s[i+1]>='0'&&s[i+1]<='9')return false;
			}
			first=false;
			a[idx]=(s[i]-'0')+a[idx]*10;
		}
		if(s[i]=='.'){
			if(!(s[i+1]>='0'&&s[i+1]<='9')){cout<<i<<' ';return false;} 
			first=true;
			cntpoint++;
			idx++;
		}
		if(s[i]==':')
		{
			if(!(s[i+1]>='0'&&s[i+1]<='9')){cout<<s[i]<<' ';return false;} 
			first=true;
			cntmaohao++;
			idx++;
		}
	}
	if(cntpoint!=3&&cntmaohao==1)return false;
	if(cntpoint!=3)return false;
	if(cntmaohao!=1)return false;
	for(int i=1;i<=4;i++)
	{
		 if(a[i]>255)return false;
		 //if(chk(a[i])==false)return false;
	}
	if(a[5]>65535)return false;
	//if(chk(a[5])==false)return false;
	return true;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>op>>ad;
		if(op=="Server")
		{
			if(check(ad))
			{
				if(now[ad]==0)
				{
					now[ad]=i;
					cout<<"OK"<<endl;
				}
				else cout<<"FAIL"<<endl;
			}
			else cout<<"ERR"<<endl;
		}
		else 
		{
			if(check(ad))
			{
				if(now[ad]!=0)cout<<now[ad]<<endl;
				else cout<<"FAIL"<<endl;
			}
			else cout<<"ERR"<<endl;
		}
	}
	return 0;
}

2021/11/22 22:24
加载中...