75分re求助
查看原帖
75分re求助
745842
zqcleo楼主2023/10/14 18:15
#include <iostream>
using namespace std;
int n, k, m;
string a[50000], b[50000];

string gl(string s) {
	for (int o = 0; o <= s.length() - 1; o++) {
		if (s[o] == '0') {
			if (s.length() > 1) {
				s.erase(o, 1);
				o--;
			} else {
				return s;
			}
		} else {
			return s;
		}
	}
}

bool bj1(string s) {
	if (s.length() > 3) {
		return 1;
	}
	if (s.length() < 3) {
		return 0;
	}
	if (s > "255") {
		return 1;
	} else {
		return 0;
	}
}

bool bj2(string s) {
	if (s.length() > 5) {
		return 1;
	}
	if (s.length() < 5) {
		return 0;
	}
	if (s > "65535") {
		return 1;
	} else {
		return 0;
	}
}

int main() {
	cin >> n;
	for (int j = 1; j <= n; j++) {
		cin >> a[j] >> b[j];
		int w = 0;
		string s1 = "", s2 = "", s3 = "", s4 = "", s5 = "";
		while (b[j][w] != '.') {
			s1 += b[j][w];
			w++;
		}
		w++;
		while (b[j][w] != '.') {
			s2 += b[j][w];
			w++;
		}
		w++;
		while (b[j][w] != '.') {
			s3 += b[j][w];
			w++;
		}
		w++;
		while (b[j][w] != ':') {
			s4 += b[j][w];
			w++;
		}
		w++;
		while (w < b[j].length() ) {
			s5 += b[j][w];
			if (w == b[j].length() - 1) {
				break;
			}
			w++;
		}
		string s6 = s1, s7 = s2, s8 = s3, s9 = s4, s0 = s5;
		s6 = gl(s6);
		s7 = gl(s7);
		s8 = gl(s8);
		s9 = gl(s9);
		s0 = gl(s0);
		if (s6 != s1 || s2 != s7 || s8 != s3 || s9 != s4 || s0 != s5) {
			cout << "ERR" << endl;
			continue;
		}
		if (bj1(s6) == 1 || bj1(s7) == 1 || bj1(s8) == 1 || bj1(s9) == 1) {
			cout << "ERR" << endl;
			continue;
		}
		if (bj2(s0) == 1) {
			cout << "ERR" << endl;
			continue;
		}
		if (a[j] == "Server") {
			for (k = 1; k < j; k++) {
				if (b[k] == b[j] && a[k] == "Server") {
					cout << "FAIL" << endl;
					break;
				}
			}
			if (k == j) {
				cout << "OK" << endl;
			}
		} else if (a[j] == "Client") {
			for ( m = 1; m < j; m++) {
				if (b[m] == b[j] && a[m] == "Server") {
					cout << m  << endl;
					break;
				}
			}
			if (m == j) {
				cout << "FAIL" << endl;
			}
		}
	}
	return 0;
}
2023/10/14 18:15
加载中...