95pts大佬求调
查看原帖
95pts大佬求调
325282
zsh1楼主2024/1/27 13:08
#include<bits/stdc++.h>
using namespace std;
struct node{
	int id;
	string ip;
}t[9999];
bool f(char a[])
{
	char b[9999];
	long long c,d,e,f,g,x=0,y=0;
	sscanf(a,"%d.%d.%d.%d:%d",&c,&d,&e,&f,&g);
	sprintf(b,"%d.%d.%d.%d:%d",c,d,e,f,g);
	for(int i=0;i<strlen(a);i++)
	{
		if(a[i]=='.')x++;
		if(a[i]==':')y++;
	}
	if(x==3&&y==1&&strlen(a)==strlen(b)&&c>=0&&c<=255&&d>=0&&d<=255&&e>=0&&e<=255&&f>=0&&f<=255&&g>=0&&g<=65535)return 1;
	return 0;
}
int main()
{
	int n,k=0;
	cin>>n;
	char a[n+1],h[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>h>>a;
		if(!f(a))
		{
			cout<<"ERR"<<endl;
			continue;
		}
		if(h[0]=='S')
		{
			bool ff=1;
			for(int i=1;i<=k;i++)
			{
				if(a==t[i].ip)
				{
					ff=0;
					cout<<"FAIL"<<endl;
					break; 
				} 
			}
			if(ff)
			{
				k++;
				t[k].id=i;
				t[k].ip=a;
				cout<<"OK"<<endl;
			}
		}
		else
		{
			bool ff=1;
			for(int i=1;i<=k;i++)
			{
				if(a==t[i].ip)
				{
					cout<<t[i].id<<endl;
					ff=0;
					break;
				}
			}
			if(ff)cout<<"FAIL"<<endl;
		}
	}
	return 0;
}
2024/1/27 13:08
加载中...