70pts求助
查看原帖
70pts求助
496009
黄舀啊楼主2022/4/15 17:15
#include<map>
#include<cstdio>
#include<iostream>
using namespace std;

struct node{
	int a,b,c,d,e;
};

int n;

map <string,bool> sever;
map <string,int> sever1;
map <string,bool> client;

bool check(char s[]){
	int a,b,c,d,e;
	int f = sscanf(s,"%d.%d.%d.%d:%d",&a,&b,&c,&d,&e);
	if(f != 5) return 0;
	if(a<0 || a>255) return 0;
	if(b<0 || b>255) return 0;
	if(c<0 || c>255) return 0;
	if(d<0 || d>255) return 0;
	if(e<0 || e>65535) return 0;
	return 1;
}

int main(){
//	freopen("network.in","r",stdin);
//	freopen("network.out","w",stdout);
	cin >> n;
	for(int i=1 ; i<=n ; i++){
		char kind[1005],ask[1005];
		cin >> kind >> ask;
		bool flag = check(ask);
		string t = string(ask);
		if(!flag) cout << "ERR" << endl;
		else {
			if(kind[0] == 'S'){
				if(sever[t] != 1){
					sever1[t] = i;
					cout << "OK" << endl;
					sever[t] = 1;
				} else {
					cout << "FAIL" << endl;
				}
			} else {
				if(sever[t] == 1){
					cout << sever1[t] << endl;
					client[t] = 1;
				} else {
					cout << "FAIL" << endl;
				}
			}
		}
	}
//	fclose(stdin);
//	fclose(stdout);
	return 0;
} 
2022/4/15 17:15
加载中...