(玄关)90分,WA#13,#19求助
查看原帖
(玄关)90分,WA#13,#19求助
1328579
mairuisheng楼主2024/8/23 20:45

记录

#include<iostream>
#include<cstring>
using namespace std;
long long slow;
long long n,c1,c2,i,j,k,g,sum;
bool flag2;
string s,x;
struct one_to_one
{
	string l;
	long long num;
}com[1001];
bool check(string s2)
{
	int i;
	for(i=1;i<=g;++i)if(com[i].l==s2)return false;
	return true;
}
int judge(string s2)
{
	int i;
	for(i=1;i<=g;++i)if(com[i].l==s2)return com[i].num;
	return -1;
}
int main()
{
	scanf("%lld",&n);
	for(i=1;i<=n;++i)
	{
		flag2=false;
		cin>>s>>x;
		c1=c2=k=slow=sum=0;
		for(j=0;j<x.length();++j)
		{
			if(x[j]=='.')c1++;
			else if(x[j]==':'&&c1==3)c2++;
		}
		if(c1!=3||c2!=1)
		{
			puts("ERR");
			continue;
		}
		bool flag=false;
		bool flag3=false;
		for(j=0;j<x.length();++j)
		{
			if(x[j]>='0'&&x[j]<='9')
			{
				if(!flag&&x[j]=='0')flag3=true;
				if(flag&&flag3)
				{
					flag2=true;
					break;
				}
				slow=slow*10+(x[j]-48);
				if(slow>65536)
				{
					flag2=true;
					break;
				}
				sum++;
				flag=true;
			}
			else
			{
				++k;
				if(slow<0||slow>255||(sum==0&&slow==0))
				{
					flag2=true;
					break;
				}
				sum=slow=0;
				flag=flag3=false;
			}
		}
		if(slow<0||slow>65535||!flag)flag2=true;
		if(flag2)
		{
			puts("ERR");
			continue;
		}
		if(s=="Server")
		{
			if(!check(x))
			{
				puts("FAIL");
				continue;
			}
			puts("OK");
			com[++g].l=x;
			com[g].num=i;
		}
		else if(s=="Client")
		{
			int r=judge(x);
			if(r==-1)
			{
				puts("FAIL");
				continue;
			}
			else printf("%lld\n",r);
		}
	}
	return 0;
}
2024/8/23 20:45
加载中...