TA 在 赣 神 魔?
查看原帖
TA 在 赣 神 魔?
416242
New_hope楼主2022/8/27 16:12
#include<bits/stdc++.h>
#include<map>

using namespace std;


bool check(string a);
map<string,int> mapServer;

int main(){
	
	int n;
	int i;
	cin >> n;
	for(i = 1; i <= n; i ++){
		string op,ad;
		cin >> op >> ad;
		cout << i << " ";
		if(i == 99){
			cout << ad << endl;
		}
		if(!check(ad)){
			cout << "ERR" << endl;
			continue;
		}
		
		if(op == "Server"){
			if(mapServer[ad]){
				cout << "FAIL" << endl;
				continue;
			}
			mapServer[ad] = i;
			cout << "OK" << endl;
		}
		else if(op == "Client"){
			if(mapServer[ad] == 0){
				cout << "FAIL" << endl;
			}
			else cout << mapServer[ad] << endl;
		}
		
	}
	
	return 0;
}

bool check(string a){
	int i,l;
	int t1,t2;//t1->.,t2->:
	l = a.size();
	t1 = t2 = 0;
	
	for(i = 0; i < l; i ++){
		int num;
		if(a[i] == '0'){
			if(a[i+1] == '.'||a[i+1] == ':'){
				num = 0;
			}
			else return 0;
		}
		else{
			
			num = 0;
			while(a[i] >= '0' && a[i] <= '9'){
				num = num*10 + int(a[i] - '0');
				i ++;
			}
			
			if(a[i] == '.'){
				t1 ++;
				if(num < 0 || num > 255){
					return 0;
				}
			}
			else if(a[i] == ':'){
				if(i == l - 1){
					return 0;
				}
				t2 ++;
			}	
			else{
				if(num < 0 || num > 65535){
					return 0;
				}
			}
			if(t1 < 3 && t2 >= 1){
				return 0;
			}
		}
		// cout << num << endl;
	}
	// cout << "t1 = " << t1 << endl << "t2 = " << t2 << endl;
	if(t1 != 3 || t2 != 1){
		return 0;
	}
	return 1;
}

跪求hack数据,球球了(主要是ERR和FAIL的问题)

2022/8/27 16:12
加载中...