蒟蒻求助判断ERR
查看原帖
蒟蒻求助判断ERR
594916
OcTar楼主2023/10/4 18:59

rt,判断 ERR 时错了。

code\text{code}:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define ERR cout<<"ERR"<<endl
#define FAIL cout<<"FAIL"<<endl
#define OK cout<<"OK"<<endl
int n, scnt;
map<string, bool> mp, mp2;
map<string, int> id;
//39.88.149.216:8888
bool f(ll x) {
	return 0 <= x && x <= 255;
}
bool check(string s) {
	int pcnt = 0;
	ll a[6] = {0, 0, 0, 0, 0, 0};
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '.') {
			++pcnt;
		}
		if (s[i] == ':' && pcnt < 3) {
			return false;
		}
	}
	if (pcnt > 3) {
		return false;
	}
	int dcnt = 6;
	string ss = ":";
	ss += s;
	for (int i = ss.size() - 1; i >= 0; i--) {
		int j = i, d = 1;
		ll num = 0;
		--dcnt;
		while (ss[j] != '.' && ss[j] != ':') {
			num += d * (ss[j] - '0');
			d *= 10;
			--j;
			if (dcnt == 1 || dcnt == 2 || dcnt == 3 || dcnt == 4) {
				if (num > 255) {
					return false;
				}
			} else if (dcnt == 5) {
				if (num > 65535) {
					return false;
				}
			}
		}
		if (ss[j + 1] == '0' && num != 0) {
			return false;
		}
		a[dcnt] = num;
		i = j;
	}
	if (f(a[1]) && f(a[2]) && f(a[3]) && f(a[4]) && 0 <= a[5] && a[5] <= 65535) {
		return true;
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		string op, ad;
		cin >> op >> ad;
		if (op == "Server") {
			if (!check(ad)) {
				ERR;
			} else if (!mp.count(ad)) {
				OK;
				id[ad] = i;
				mp[ad] = 1;
			} else {
				FAIL;
			}
		} else {
			if (!check(ad)) {
				ERR;
			} else if (!mp.count(ad)) {
				FAIL;
			} else {
				cout << id[ad] << endl;
			}
		}
	}
	return 0;
}
2023/10/4 18:59
加载中...