s0 #1 TLE?? 求助
查看原帖
s0 #1 TLE?? 求助
126010
weijie楼主2021/11/15 14:26

rt

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
map<string,int> F;
void input(int k) {
	char ch[50],ipt; int x[50],cnt=1,tot=0; bool f=0;
	memset(x,-1,sizeof(x));
	scanf("%s ",ch+1);
	string str;str.clear();
	while((ipt=getchar())!=10) {
		str+=ipt;
		if(f) continue;
		if(x[cnt]==0 && ipt>='0' && ipt<='9') {
			f=1;
			continue;
		}
		if(x[cnt]==-1 && (ipt==':' || ipt=='.')) {
			f=1;
			continue;
		}
		if(x[cnt]==-1) {
			x[cnt]=ipt-'0',tot++;
			continue;
		}
		if((cnt<=4 && tot>=4) || (cnt==5 && (tot>=6 || ipt=='.' || ipt==':'))) {
			f=1;
			continue;
		}		
		if(cnt<=3 && ipt==':') {
			f=1;
			continue;
		}
		if(cnt<=3 && ipt=='.') {
			if(x[cnt]>255) f=1;
			++cnt,tot=0,x[cnt]=-1;
			continue;
		}
		if(cnt==4 && ipt=='.') {
			f=1;
			continue;
		}
		if(cnt==4 && ipt==':') {
			if(x[cnt]>255) f=1;
			++cnt,tot=0,x[cnt]=-1;
			continue;
		}
		x[cnt]=x[cnt]*10+ipt-'0',tot++;
	}
	if(x[cnt]>65535 || cnt<5 || x[cnt]==-1) f=1;
	if(f) {
		printf("ERR\n");
		return;
	}	
	if(ch[1]=='S') {
		if(F[str]) printf("FAIL\n");
		else {
			F[str]=k;
			printf("OK\n");
		}
		return;
	}
	if(ch[1]=='C') {
		if(F[str]) printf("%d\n",F[str]);
		else printf("FAIL\n");
		return;
	}
	return;
}
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) input(i);
	return 0;
}

record

2021/11/15 14:26
加载中...