只能过11个点,求助
查看原帖
只能过11个点,求助
486166
Incin楼主2021/10/29 20:36
#include<bits/stdc++.h>
using namespace std;

const int N = 1010;

typedef long long LL;

int n;
string server[N];

bool ifeach(string str)
{
	int p = atoi(str.c_str());
	if(p < 0 || p > 255)return false;
	
	return true;
}
bool ifeach1(string str)
{
	if(str.size() > 1 && str[0] == '0')
		return false;
	
	return true;
	
}
int main()
{
	cin>>n;
	getchar();
	for(int idx = 1;idx<=n;idx++)
	{
		int j;
		string str;
		
		getline(cin,str);
		string sc,ip,port;
		int g = 0,f = 0;
		
		for(int i =0;i<str.size();i++)
		{
			if(str[i] == '.') g++;
			
			if(str[i] == ' ')
			{
				sc = str.substr(0,i);
				j = i+1;
				
			}
			if(str[i] == ':')
			{
				f++;
				ip = str.substr(j,i - j);
				
				port  = str.substr(i+1);
			}
		}
		if(g != 3 || f != 1)
		{
			cout<<"ERR"<<endl;
			continue;
		}
		int pt = atoi(port.c_str());
		if(pt<0 || pt>65535 || !ifeach1(port))
		{
			cout<<"ERR"<<endl;
			continue;
		}
		
		string c;
		int a,b;
		for(a =0,b = 0;a<ip.size();a++)
		{
			if(ip[a] == '.')
			{
				c = ip.substr(b,a-b);
				b = a+1;
				if(!ifeach(c) || !ifeach1(c))
				{
					cout<<"ERR"<<endl;
					continue;
				}	
			}
		}
		c = ip.substr(b);
		if(!ifeach(c) || !ifeach1(c))
		{
			cout<<"ERR"<<endl;
			continue;
		}
		
		if(sc == "Server")
		{
			string ipaddr = ip + ":" + port;
			bool ser = false;
			for(int i =1;i<idx;i++)
			{
				if(server[i] == ipaddr)
				{
					ser = true;
					cout<<"FAIL"<<endl;
					break;
				}
			}
		
			if(!ser)
			{
				server[idx] = ipaddr;
				cout<<"OK"<<endl;	
			}	
		}	
		else
		{
			string claddr =  ip + ":" + port;
			bool cer = false;
			for(int i =1;i<idx;i++)
			{
				if(server[i] == claddr)
				{
					cer = true;
					cout<<i<<endl;
					break;
				}
			}
			if(!cer)cout<<"FAIL"<<endl;
		}
	}	
	return  0; 
} 
2021/10/29 20:36
加载中...