求助80分
查看原帖
求助80分
428358
Grisses楼主2021/11/5 21:02
#include<bits/stdc++.h>
using namespace std;
int n;
map<string,int>m;
signed main()
{
//	freopen("network.in","r",stdin);
//	freopen("network.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		char c[30],s[30];
		scanf("%s%s",c+1,s+1);
		int len=strlen(s+1);
		string S="";
		for(int j=1;j<=len;j++)S+=(char)s[j];
		string st="";
		int a[10]={0},tot=0;
		bool f=1;
		for(int j=1;j<=len;){
			if(s[j]>='0'&&s[j]<='9'){
				tot++;
				int k=j;
				while(s[j]>='0'&&s[j]<='9')a[tot]=a[tot]*10+(s[j]-'0'),j++;
				if((int)log10(a[tot])+1ll<j-k){
					printf("ERR\n");
					f=0;
					break;
				}
				if(a[tot]==0&&j-k!=1){
					printf("ERR\n");
					f=0;
					break;
				}
				if(tot>5){
					printf("ERR\n");
					f=0;
					break;
				}
			}
			else if(s[j]=='.'){
				if(s[j-1]=='.'||s[j-1]==':'){
					f=0;
					printf("ERR\n");
					break;
				}
				st+='.';
				j++;
			}
			else if(s[j]==':'){
				if(s[j-1]=='.'||s[j-1]==':'){
					f=0;
					printf("ERR\n");
					break;
				}
				st+=':';
				j++;
			}
		}
		if(f==1){
			for(int j=1;j<=5;j++){
				if(j<=4){
					if(a[j]>=0&&a[j]<=255);
					else{
						tot=0;
						break;
					}
				}
				if(j==5){
					if(a[j]>=0&&a[j]<=65535);
					else{
						tot=0;
						break;
					}
				}
			}
			if(st=="...:"&&tot==5){
				if(c[1]=='S'){
					if(m.count(S)==0){
						printf("OK\n");
						m[S]=i;
					}
					else{
						printf("FAIL\n");
					}
				}
				if(c[1]=='C'){
					if(m.count(S)==1){
						printf("%d\n",m[S]);
					}
					else{
						printf("FAIL\n");
					}
				}
			}
			else{
				printf("ERR\n");
			}
		}
	}
	return 0;
}

评测

2021/11/5 21:02
加载中...