65 pts,求助!
查看原帖
65 pts,求助!
814343
bc2_cryeggy楼主2023/2/14 19:00

代码:

#include<bits/stdc++.h>
using namespace std;
#define qwq ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

bool check(string ip_addr)
{
	int a = -1, b = -1, c = -1, d = -1, e = -1;
	sscanf(ip_addr.c_str(), "%d.%d.%d.%d:%d", &a, &b, &c, &d, &e);
	if (a < 0 || b < 0 || c < 0 || d < 0 || e < 0)
		return 0;
	if (a > 255 || b > 255 || c > 255 || d > 255)
		return 0;
	if (e > 65535)
		return 0;
	char str[100];
	sprintf(str, "%d.%d.%d.%d:%d", a, b, c, d, e);
	if (str == ip_addr)
		return 1;
} 

int main() 
{
	qwq;
	int n;
	cin >> n;
	unordered_map<string, int> hash_map;
	for (int i = 1; i <= n; i ++)
	{
		string opt, ip_addr;
		cin >> opt >> ip_addr;
		if (opt == "Server")
		{
			if (!check(ip_addr))
				cout << "ERR" << endl;
			else if (hash_map.count(ip_addr))
				cout << "FAIL" << endl;
			else
			{
				hash_map[ip_addr] = i;
				cout << "OK" << endl;
			}
		}
		else
		{
			if (!check(ip_addr))
				cout << "ERR" << endl;
			else if (!hash_map.count(ip_addr))
				cout << "FAIL" << endl;
			else
				cout << hash_map[ip_addr] << endl;
		}
	}
	return 0;
}

qwqqwq

2023/2/14 19:00
加载中...