70分求助
查看原帖
70分求助
564225
dontwannacry楼主2022/7/17 15:56
#include<bits/stdc++.h>
using namespace std;
struct con{
    string re;
    string id;
}s[2010];
struct zzz{
	char c[30];
	int len = 0;
};
struct fj{
	zzz a[5];
};
fj fen(string a){
	int i = 0;
	fj f;
	for(int t = 0;t < 5&&i < a.size();++t){
		while(a[i] >= '0'&&a[i] <= '9'&&i < a.size()){
			f.a[t].c[++f.a[t].len] = a[i];
			++i;
		}
		f.a[t].c[++f.a[t].len] = a[i];
		++i;
	}
	return f;
}
bool result(string id){
	fj f = fen(id);
	for(int t = 0;t < 5;++t){
		if(f.a[t].len > 2&&f.a[t].c[1] == '0'){
			return 0;
		}
	}
	for(int t = 0;t < 3;++t){
		if(f.a[t].c[f.a[t].len] != '.'||f.a[t].len <= 1){
			return 0;
		}
		int x = 0;
		for(int i = 1;i < f.a[t].len;++i){
			x *= 10;
			x += f.a[t].c[i] - '0';
		}
		if(x > 255){
			return 0;
		}
	}
	if(f.a[3].c[f.a[3].len] != ':'||f.a[3].len <= 1){
		return 0;
	}
	int x = 0;
	for(int i = 1;i < f.a[3].len;++i){
		x *= 10;
		x += f.a[3].c[i] - '0';
	}
	if(x > 255){
		return 0;
	}
	x = 0;
	for(int i = 1;i < f.a[4].len;++i){
		x *= 10;
		x += f.a[4].c[i] - '0';
	}
	if(x > 65535){
		return 0;
	}
	if(f.a[4].len <= 1){
		return 0;
	}
	return 1;
}
int find(int x){
	for(int i = 1;i < x;++i){
		if(s[i].id == s[x].id&&s[i].re == "Server"){
			return i;
		}
	}
	return 0;
}
int n;
int main(){
	//freopen("1.in","r",stdin);
    scanf("%d",&n);
    for(int i = 1;i <= n;++i){
        cin >> s[i].re >> s[i].id;
        if(result(s[i].id)){
        	if(s[i].re=="Server"){
        		if(find(i) != 0){
					cout << "FAIL\n";
				}else{
					cout << "OK\n";
				}
        	}else{
        		int x = find(i);
        		if(x != 0){
					cout <<x<< "\n";
				}else{
					cout << "FAIL\n";
				}
        	}
        }else{
        	cout << "ERR\n";
        }
    }
    return 0;
}
2022/7/17 15:56
加载中...