《 警 示 后 人 》
  • 板块灌水区
  • 楼主shijihong
  • 当前回复3
  • 已保存回复3
  • 发布时间2021/10/25 12:39
  • 上次更新2023/11/4 02:18:48
查看原帖
《 警 示 后 人 》
383601
shijihong楼主2021/10/25 12:39
#include <iostream>
#include <cstring>
#include <map>
using namespace std;
map<string,int> vis_server;
bool check_it(string s){
	if(s[0]<'0' or s[0]>'9') return false;
	int cnt_dot=0,cnt_mark=0;
	bool flag=false;
	for(int i=0;i<int(s.length());i++){
		if(s[i]=='.' and !flag) cnt_dot++;
		else if(s[i]==':'){
			cnt_mark++;
			flag=true;
		} 
		else if(s[i]=='.' and flag) return false;
		else if(s[i]<'0' or s[i]>'9') return false;
	}
	if(cnt_dot!=3 or cnt_mark!=1) return false;
	return true;
}
int cnt=0;
int check_num(string s){
	while(s[cnt]<'0' or s[cnt]>'9') cnt++;
	if(s[cnt]=='0' and cnt+1<int(s.length()) and s[cnt+1]>='0' and s[cnt+1]<='9') return -1;
	int num=0;
	while(s[cnt]>='0' and s[cnt]<='9' and cnt<int(s.length())){
		num=(num<<1)+(num<<3)+s[cnt]-'0';
		if(num>65535) return -1;
		cnt++;
	}
	return num;
}
int main(){
  	freopen("network.in","r",stdin);
  	freopen("networ.out","w",stdout);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		string op,ad;
		cin>>op>>ad;
		cnt=0;
		if(!check_it(ad)){
			cout<<"ERR"<<endl;
			continue;
		}
		int num1=check_num(ad),num2=check_num(ad),num3=check_num(ad),num4=check_num(ad),num5=check_num(ad);
		if(num1<0 or num2<0 or num3<0 or num4<0 or num5<0){
			cout<<"ERR"<<endl;
			continue;
		}
		if(num1>255 or num2>255 or num3>255 or num4>255 or num5>65535){
			cout<<"ERR"<<endl;
			continue;
		}
		if(op=="Server"){
			if(vis_server[ad]!=0){
				cout<<"FAIL"<<endl;
				continue;
			}
			vis_server[ad]=i;
			cout<<"OK"<<endl;
		}
		if(op=="Client"){
			if(!vis_server[ad]){
				cout<<"FAIL"<<endl;
				continue;
			}
			cout<<vis_server[ad]<<endl;
		}
	}
	return 0;
} 

这是一份爆零代码

2021/10/25 12:39
加载中...