hack 测试点 RE
查看原帖
hack 测试点 RE
373207
Ntoskrnl楼主2023/8/23 00:46

本地不RE, WSL Ubuntu 22.04 不RE,就洛谷(还有洛谷的IDE)RE!!!

hack数据hack了个啥呀:

Server 1921168.1.1:8080
Server 192.16811.1:8080
Server 192.168.111:8080

这三个ERR有这么难弄吗?!?!

本人智障,没用map,用了set,不过也一样

#include <cstdio>
#include <cstring>
#include <set>
using namespace std;
class ipv4{
public:
	unsigned int ip,code;
	unsigned short int port;
	bool operator<(const ipv4 &tar)const{
		if(ip!=tar.ip)
			return ip<tar.ip;
		else
			return port<tar.port;
	}
};
set<ipv4> online;
int n;
char op[1024],ad[1024];
bool err;
ipv4 anal(){
	ipv4 res;
	res.ip=0;
	res.port=0;
	err=false;
	
	int cnt1=0,cnt2=0;
	for(int i=0;i<strlen(ad);i++)
		if(ad[i]=='.')
			cnt1++;
		else if(ad[i]==':')
			cnt2++;
    //printf("%d %d\n",cnt1,cnt2);
	if(cnt1!=3 || cnt2!=1){
		err=true;
		return res;
	}
	
	unsigned long long int a,b,c,d,e;
	int rtn=sscanf(ad,"%llu.%llu.%llu.%llu:%llu",&a,&b,&c,&d,&e);
	if(rtn!=5){
		err=true;
		return res;
	}
	else if(a>255 || b>255 || c>255 || d>255 || e>65535){
		err=true;
		return res;
	}
	
	char *ptr=ad;
	while(*ptr!=':')ptr++;
	ptr++;
	while(*ptr>='0' && *ptr<='9')ptr++;
	if(*ptr!=0){
		err=true;
		return res;
	}
	
	if(ad[0]=='0' && ad[1]!='.'){
		err=true;
		return res;
	}
	for(int i=0;i<strlen(ad);i++)
		if((ad[i]=='.' || ad[i]==':') && ad[i+1]=='0')
			if(i+2<strlen(ad))
				if(ad[i+2]!='.' && ad[i+2]!=':'){
					err=true;
					return res;
				}
	
	res.ip=(a<<24)+(b<<16)+(c<<8)+d;
	res.port=e;
	return res;
}
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%s",op);
		getchar();
		char *ptr=ad,ch;
		while(true){
			ch=getchar();
            //printf("get %d(%c)\n",ch,ch);
			if(ch!='\n' && ch!='\r'){
				*ptr=ch;
				ptr++;
			}
			else break;
		}
		*ptr=0;
		
		if(!strcmp(op,"Server")){
			ipv4 res=anal();
			if(err)
				puts("ERR");
			else if(online.count(res))
				puts("FAIL");
			else{
				res.code=i+1;
				online.insert(res);
				puts("OK");
			}
		}
		else{
			ipv4 res=anal();
			if(err)
				puts("ERR");
			else if(!online.count(res))
				puts("FAIL");
			else
				printf("%d\n",online.find(res)->code);
		}
	}
}
2023/8/23 00:46
加载中...