样例能过,0分求调
查看原帖
样例能过,0分求调
1068194
H_M_B_C_楼主2024/7/5 01:02

代码如下

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

int n,l_ser=0;

struct node{
	string ip;
	int bh;
}ser[1005];

bool pan (string s) {
	int m=0,dc=0,mc=0,k=0;
	for (int i=0;i<s.length();i++) {
		if (s[i] >= '0' && s[i] <= '9') {
			if (m==0 && s[i]=='0' && s[i+1] >='0' && s[i+1] <= '9') {
				return false;
			}
			m = m*10 + s[i] - '0';
			if (k < 4 && m > 255) return false;
			if (k==4 && m > 65535) return false; 
		}
		if (s[i] == '.') {
			dc++;
		}
		if (s[i] == ':') {
			mc++;
		}
		if (mc > 0 && dc < 3) return false;
		if ((s[i] == '.' || s[i] == ':') && (i==0 || i == s.length()-1)) return false;
		if (s[i] == '.' || s[i] == ':') {
			m=0;
			k++;
			if (s[i-1]=='.') return false;
		}
	}
	if (dc != 3 || mc != 1) return false;
	if (k < 4) return false;
	
	return true;
}

int main() {
    string name,pi;
	cin >> n;
	for (int i=1;i<=n;i++) {
		cin >> name;
		cin >> pi;
		if (pan(pi)) {
			bool flag=false;
			int j;
			for (j=1;j<=l_ser;j++) {
				if (ser[j].ip == pi) {
					flag=true;
					break;
				}
			}
			if (flag) {
				if (name == "Server") {
					cout << "FAIT" << endl;
				}else {
					cout << ser[j].bh << endl;
				}
			}else {
                if (name == "Server") {
                	l_ser++;
                	ser[l_ser].ip = pi;
					ser[l_ser].bh = i; 
					cout << "OK" << endl;
				}else {
					cout << "FAIT" << endl;
				}
			}
		}else {
			cout << "ERR" << endl;
		}
	}
    return 0;
}
2024/7/5 01:02
加载中...