80 求助
查看原帖
80 求助
542974
William_qwq楼主2021/12/4 22:46
#include<bits/stdc++.h>
using namespace std;
bool allow(string s)
{
	long long cnt=0;
	string a,b,c,d,e;
	long long i,flg1=0,flg2=0;
	for(i=0;i<s.size();i++)
	{
		if(s[i]=='.') flg1++;
		if(s[i]==':') flg2++;
	}
	if(flg1!=3) return 0;
	if(flg2!=1) return 0;
	while(s[cnt]!='.')
	{
		a+=s[cnt];
		cnt++;
	}
	cnt++;
	while(s[cnt]!='.')
	{
		b+=s[cnt];
		cnt++;
	}
    cnt++;
	while(s[cnt]!='.')
	{
		c+=s[cnt];
		cnt++;
	}
	cnt++;
	while(s[cnt]!=':')
	{
		d+=s[cnt];
		cnt++;
	}
	cnt++;
	while(cnt<s.size())
	{
		e+=s[cnt];
		cnt++;
	}
	if(a[0]=='0'&&a.size()!=1) return 0;
	if(b[0]=='0'&&b.size()!=1) return 0;
	if(c[0]=='0'&&c.size()!=1) return 0;
	if(d[0]=='0'&&d.size()!=1) return 0;
	if(e[0]=='0'&&e.size()!=1) return 0;
	long long ia,ib,ic,id,ie;
	stringstream sa,sb,sc,sd,se;
	sa<<a;
	sa>>ia;
	sb<<b;
	sb>>ib;
	sc<<c;
	sc>>ic;
	sd<<d;
	sd>>id;
	se<<e;
	se>>ie;
	if(ia<0||ia>255) return 0;
	if(ib<0||ib>255) return 0;
	if(ic<0||ic>255) return 0;
	if(id<0||id>255) return 0;
	if(ie<0||ie>65535) return 0;
	return 1;
}
map<string,long long> m;
int main()
{
    long long n,i,j,k;
    string t,s;
    cin>>n;
    for(i=1;i<=n;i++)
    {
    	cin>>t>>s;
    	if(t=="Server")
    	{
    		if(allow(s))
    		{
    			if(!m.count(s))
    			{
    				cout<<"OK"<<endl;
    				m[s]=i;
				}
				else cout<<"FAIL"<<endl;
			}
			else cout<<"ERR"<<endl;
		}
		if(t=="Client")
		{
			if(allow(s))
			{
				if(m.count(s))
				{
					cout<<m[s]<<endl;
				}
				else cout<<"FAIL"<<endl;
			}
			else cout<<"ERR"<<endl;
		}
	}
	return 0;
}

2021/12/4 22:46
加载中...