求助各位大佬
查看原帖
求助各位大佬
526163
JwJ_2010楼主2021/10/26 10:59
#include<bits/stdc++.h>
using namespace std;
int check(string s)
{
	if(s[0]>'9'||s[0]<'1')return 0;
	int p=0,a=0;
	while(isdigit(s[p])){a=a*10+(s[p]-'0');p++;}
	if(a>255)return 0;
	if(s[p]!='.')return 0;
	p++;
	if(s[p]>'9'||s[p]<'1')return 0;
	int b=0;
	while(isdigit(s[p])){b=b*10+(s[p]-'0');p++;}
	if(b>255)return 0;
	if(s[p]!='.')return 0;
	p++;
	if(s[p]>'9'||s[p]<'1')return 0;
	int c=0;
	while(isdigit(s[p])){c=c*10+(s[p]-'0');p++;}
	if(c>255)return 0;
	if(s[p]!='.')return 0;
	p++;
	if(s[p]>'9'||s[p]<'1')return 0;
	int d=0;
	while(isdigit(s[p])){d=d*10+(s[p]-'0');p++;}
	if(d>255)return 0;
	if(s[p]!=':')return 0;
	p++;
	if(s[p]>'9'||s[p]<'1')return 0;
	int e=0;
	while(isdigit(s[p])){e=e*10+(s[p]-'0');p++;}
	if(e>65535)return 0;
	if(p!=s.size())return 0;
	return 1;
}
int main()
{
    //freopen("network.in","r",stdin);
   // freopen("network.out","w",stdout);
    map<string,int>used;
    int n;
    cin>>n;
    string s,ss;
    for(int i=1;i<=n;i++)
    {
    	cin>>ss>>s;
        if(!check(s))
        {
        	cout<<"ERR"<<endl;
        	continue;
		}
		if(ss=="Server")
			{
				if(used[s])cout<<"FAIL";
				else 
				{
					cout<<"OK";
					used[s]=i;
				}
		    }
		    else
		    {
		    	if(used[s])cout<<used[s];
		    	else cout<<"FAIL";
			}
			cout<<endl;
		}
	return 0;
}
2021/10/26 10:59
加载中...