25pts,悬关
查看原帖
25pts,悬关
760171
Binah_cyc楼主2023/8/10 13:05

大红大紫,代码有亿点恶臭,求改

#include <bits/stdc++.h>
using namespace std;
map<string,int> mp;
int n,cnt;
string op;
bool check(string ad)
{
	ad+=":";
	long long a=0,b=0;
	if(ad[b]=='0')
	{
		cout<<"ERR\n";
		return 0;
	}
	for(int qaz=1;qaz<=3;qaz++)
	{
		while(ad[b]!='.')
		{
			a=a*10+(ad[b]-'0');
			b++;
		}
		if(a>255)
		{
			cout<<"ERR\n";
			return 0;
		}
		b++;
		a=0;
	}
	while(ad[b]!=':')
	{
		a=a*10+(ad[b]-'0');
		b++;
	}
	if(a>255)
	{
		cout<<"ERR\n";
		return 0;
	}
	b++;
	a=0;
	while(ad[b]!=':')
	{
		a=a*10+(ad[b]-'0');
		b++;
	}
	if(a>65535)
	{
		cout<<"ERR\n";
		return 0;
	}
	return 1;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>op;
		if(op=="Server")
		{
			cin>>op;
			if(check(op))
			{
				if(mp.find((op))==mp.end())
				{
					mp[op]=i;
					cout<<"OK\n";
				}
				else
				cout<<"FAIL\n";
			}
		}
		else
		{
			cin>>op;
			if(check(op))
			{
				if(mp.find((op))!=mp.end())
				{
					map<string, int>::iterator it=mp.find(op);
					cout<<it->second<<'\n';
				}
				else
				cout<<"FAIL\n";
			}
		}
	}
	return 0;
}
2023/8/10 13:05
加载中...