65分,求助
查看原帖
65分,求助
727348
Dreamcatching楼主2022/10/18 14:40

13,14,17,18,19,20,21WA了,好像是ERR没判对

#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
map<string,int>q;
int n;
string a,b;
bool check(string x){
	int sum1=0,sum2=0,s=0;
	int len=x.size();
	if(x[0]=='.'||x[len-1]==':'){return 0;}
	for(int i=0;i<len;i++){
		if(x[i]=='.'||x[i]==':'){
			if(x[i]=='.'){
				sum1++;
				if(x[i+1]=='.'||x[i+1]==':'){return 0;}
			}	
			else sum2++;
			if(s>255){return 0;}
			s=0;
		}else{s=s*10+(x[i]-'0');}
		if((x[i-1]=='.'||x[i-1]==':')&&x[i]=='0'&&x[i+1]!='.'&&x[i+1]!=':'&&i+1<len){return 0;}
	}
	if(s>65535){return 0;}
	if(sum1==3&&sum2==1){return 1;}
	return 0;
}
inline int read(){
	int s=0,w=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
int main(){
	n=read();
	for(int i=1;i<=n;i++){
		cin>>a>>b;
		if(!check(b)){printf("ERR\n");}
		else{
			if(a[0]=='S'){
				if(q[b]){printf("FAIL\n");}
				else{
					printf("OK\n");
					q[b]=i;
				}
			}else{
				if(q[b]){printf("%d\n",q[b]);}
				else{printf("FAIL\n");}
			}
		}
	}
	return 0;
}

2022/10/18 14:40
加载中...