network所有民间数据都是100,CCF变85这回事
查看原帖
network所有民间数据都是100,CCF变85这回事
240191
MY(一名蒟蒻)楼主2021/10/30 20:56

network

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>

using namespace std;

map <string,int> fuwu;

char op[20];
string s;

bool check()
{
	//1
	int cnt1=0,cnt2=0,n=s.size();
	if(n < 9) return false;
	for(int i=0;i<n;i++)
	{
		if(s[i] == ':' && cnt1 < 3) return false;
		if(s[i] == '.')
		{
			if(cnt1 >= 3 || i == 0 || i == n-1 || (s[i-1] > '9' || s[i-1] < '0') || (s[i+1] < '0' || s[i+1] > '9'))
				return false;
			cnt1++;
		}
		if(s[i] == ':')
		{
			if(cnt2 || cnt1^3 || i == n-1 || (s[i-1] > '9' || s[i-1] < '0') || (s[i+1] < '0' || s[i+1] > '9')) return false;
			cnt2++;
		}
	}
//	printf("ababababba\n");
	//2
	int x,j=0;
	for(int i=0;i<4;i++)
	{
		x=0;
		while(j < n && (s[j] < '0' || s[j] > '9')) j++;
		while(j < n && s[j] >= '0' && s[j] <= '9')
		{
			x=x*10+(s[j]-'0');
			j++;
			if(x > 255 || x < 0) return false;
		}
		
	}
//	printf("ababababba\n");
	x=0;
	while(j < n && (s[j] < '0' || s[j] > '9')) j++;
	while(j < n && s[j] >= '0' && s[j] <= '9')
	{
		x=x*10+s[j]-'0';
		j++;
		if(x > 65535 || x < 0) return false;
	}
	//3
	for(int i=0;i<n;i++)
	{
		if(s[i] == '0')
		{
			if(i == 0)
			{
				if(s[i+1] >= '0' && s[i+1] <= '9') return false; 
			}
			else if(i != n-1)
			{
				if((s[i-1] < '0' || s[i-1] > '9') && (s[i+1] >= '0' && s[i+1] <= '9')) return false;
			}
		}
	}
	return true;
}

int main()
{
	freopen("network.in","r",stdin); freopen("network.out","w",stdout);
	int n;
	scanf("%d",&n);
//	printf("%d\n",n);
	for(int i=1;i<=n;i++)
	{
		scanf(" %s",op);
		cin >> s;
//		printf("%s ",op);
//		cout << s << endl;
		
		if(!check()) {printf("ERR\n"); continue;}
		
		if(op[0] == 'S')
		{	
			if(fuwu.count(s)) printf("FAIL\n");
			else {fuwu[s]=i; printf("OK\n");}
			//ERR
		}
		else
		{
			if(fuwu.count(s)) printf("%d\n",fuwu[s]);
			else printf("FAIL\n");
			//ERR
		}
	}
	fclose(stdin); fclose(stdout);
	return 0;
}

不是很懂

2021/10/30 20:56
加载中...