65pts求条,真没想明白哪错了
查看原帖
65pts求条,真没想明白哪错了
1345783
BK小鹿楼主2024/12/8 22:47

rt,马蜂有点混乱,见谅

#include <bits/stdc++.h>
using namespace std;

const int N = 1005;

int n, num, now1;

struct Kano {
	int a1, b1, c1, d1, e1, id;
}se[N], ka;

inline bool sa(Kano s1, Kano s2) {
	if (s1.a1 == s2.a1 && s1.b1 == s2.b1 && s1.c1 == s2.c1 && s1.d1 == s2.d1 && s1.e1 == s2.e1) return 1;
	return 0;
}

inline bool ck(string s, bool is_se) {
	int L = s.size();
	int cnt = 0, cnt1 = 0, a, b, c, d, e, te;
	a = b = c = d = e = 0, te = 1;
	for (int i = 0; i < L; i ++ ) {
		if (!isdigit(s[i])) {
			if (s[i] != '.' && cnt != 3) return 0;
			if (s[i] == '.') cnt ++ ;
			if (s[i] != '.' && s[i] != ':') return 0;
			if (s[i] == ':') cnt1 ++ ;
		}
	}
	
	if (cnt != 3 || cnt1 != 1) return 0;
	cnt1 = cnt = 0;
	for (int i = L - 1; i >= 0; i -- ) {
		if (s[i] == ':') cnt1 ++ , te = 1;
		if (s[i] == '.') cnt ++ , te = 1;
		if (isdigit(s[i])) {
			if (cnt1 == 0) e += (s[i] - '0') * te;
			if (cnt1 != 0 && cnt == 0) d += (s[i] - '0') * te;
			if (cnt == 1) c += (s[i] - '0') * te;
			if (cnt == 2) b += (s[i] - '0') * te;
			if (cnt == 3) a += (s[i] - '0') * te;
			te *= 10;
		}
	}
	
//	cout << a << " " << b << " " << c << " " << d << " " << e << endl;
	
	if (a < 0 || b < 0 || c < 0 || d < 0 || e < 0) return 0;
	if (a > 255 || b > 255 || c > 255 || d > 255 || e > 65535) return 0;
	
	bool fl = 0;int count = 0, kl = 1;
	for (int i = 0; i < L; i ++ ) {
		if (s[i] == '.' || s[i] == ':') fl = 0, count = 0, kl ++ ;
		if (s[i] == '0') count ++ ;
		if (isdigit(s[i]) && s[i] != '0') fl = 1;
		if ((!fl) && count) {
			if (kl == 1) if (a) return 0;
		    else if (kl == 2) if (b) return 0;
		    else if (kl == 3) if (c) return 0;
		    else if (kl == 4) if (d) return 0;
		    else if (kl == 5) if (e) return 0;
		}
	}
	
	int block = 0, nowlen = 0;
	for (int i = 0; i < L; i ++ ) {
		if (isdigit(s[i])) nowlen ++ ;
		if (s[i] == '.') {
			block ++ ;
			if (block == 1) if (!a && nowlen != 1) return 0;
			if (block == 2) if (!b && nowlen != 1) return 0;
			if (block == 3) if (!c && nowlen != 1) return 0;
			if (block == 4) if (!d && nowlen != 1) return 0;
			if (block == 5) if (!d && nowlen != 1) return 0;
			nowlen = 0;
		}
	} 
	
	if (is_se) se[++ num] = {a, b, c, d, e, now1};
	else ka = {a, b, c, d, e, 0};
	return 1;
}

int main() {
	cin.tie(0);
	cin >> n;
	while (n -- ) {
		now1 ++ ;
		string op, ed;
		cin >> op >> ed;
		if (op == "Server") {
			bool fl = ck(ed, 1);
			if (!fl) puts("ERR");
			else {
				for (int i = num - 1; i >= 1; i -- ) 
					if (sa(se[i], se[num])) {
						fl = 0;
						break;
					}
			    
			    if (fl) puts("OK");
			    else {
			    	se[num -- ] = {0, 0, 0, 0, 0, 0};
			    	puts("FAIL");
				}
			}
		} else {
			 bool fl = ck(ed, 0), fl1 = 0;
			 int id = 1;
			 if (!fl) puts("ERR");
			 else {
			 	for (int i = 1; i <= num; i ++ ) 
			 		if (sa(ka, se[i])) {
			 			fl1 = 1;
			 			id = se[i].id;
			 			break;
					 }
				
				if (!fl1) puts("FAIL");
				else cout << id << '\n';
			 }
		}
	}
	
	return 0;
}
2024/12/8 22:47
加载中...