社区讨论

《 警 示 后 人 》

灌水区参与者 3已保存回复 3

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
3 条
当前快照
1 份
快照标识符
@lobhcih7
此快照首次捕获于
2023/10/29 21:01
2 年前
此快照最后确认于
2023/11/04 02:18
2 年前
查看原帖
CPP
#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;
} 
这是一份爆零代码

回复

3 条回复,欢迎继续交流。

正在加载回复...