0分求助
查看原帖
0分求助
1000281
Y_Q_Y楼主2024/10/2 11:45
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<cstdio>
#include<ctype.h>
#include<map>
using namespace std;

map<string,int> mp;

bool check(string ad){			//是否合法 
	long long a,b,c,d,e;
	if(5 != sscanf(ad.c_str(),"%lld.%lld.%lld.%lld:%lld", &a,&b,&c,&d,&e)) return false;
	if(a < 0 || a > 255 || b < 0 || b > 255 || c < 0 || c > 255 || d < 0 || d > 255 || e < 0 || e > 65535)  return false;
	string ad_r= to_string(a)+"."+to_string(b)+"."+to_string(c)+"."+to_string(d)+":"+to_string(e);
	return ad_r==ad;
}

int main(){
	int n;
	string op;
	string ad_out;
	cin>>n;
	for(int num=1;num<=n;num++){
		cin>> op >> ad_out;
		if(check(ad_out)){        		//是否合法 
			if(op=="Server"){    //服务机 
				if(mp.count(ad_out))  cout<<"FALL\n";
				else{ mp.insert(pair<string,int>(ad_out,num)); cout<<"OK\n"; }
			}
			else{				 //客户机 
				if(mp.count(ad_out)) cout<<mp[ad_out]<<"\n";
				else cout<<"FALL\n";
			} 
		}
		else cout<<"ERR\n";
	}
	
	return 0;
}
2024/10/2 11:45
加载中...