加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

2016 百度之星 IP聚合

发布时间:2020-12-14 02:14:05 所属栏目:百科 来源:网络整理
导读:span style="font-family:Courier New;font-size:18px;"#include iostream#include cstdio#include cstdlib#include cstring#include algorithmusing namespace std;struct node {int a,b,c,d;}ip[1005],sn[55],res[1005];/*int cmp(struct node x,struct no
<span style="font-family:Courier New;font-size:18px;">#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
struct node 
{
	int a,b,c,d;
}ip[1005],sn[55],res[1005];
/*int cmp(struct node x,struct node y)
{
	if(x.a != y.a)
		return x.a < y.a;
	else if(x.b != y.b)
		return x.b  < y.b;
	else if(x.c != y.c)
		return x.c < y.c;
	else
		return x.d < y.d;
}*/
int cmp( struct node x,struct node y)
{
	if(x.a != y.a)
		return x.a < y.a ? 1:0;
	else if(x.b != y.b)
		return x.b  < y.b?1: 0;
	else if(x.c != y.c)
		return x.c < y.c?1 : 0;
	else
		return x.d < y.d? 1 : 0;
}
int main()
{
	int T,i,j,n,m,k; 
	cin >> T;
	int cnt = 0;
	while(T --)
	{
		 cnt ++;
		cin >> n >>m;//n代表ip,m代表网关
		for(i=1; i<=n; i++)
		{
			scanf("%d.%d.%d.%d",&ip[i].a,&ip[i].b,&ip[i].c,&ip[i].d);
		} 
		for(i=1; i<=m; i++)
			scanf("%d.%d.%d.%d",&sn[i].a,&sn[i].b,&sn[i].c,&sn[i].d);
		printf("Case #%d:n",cnt);
		for(i=1; i<=m; i++)
		{
			k = 0;
			for(j=1; j<=n; j++)
			{
				res[k].a = ip[j].a & sn[i].a;
				res[k].b = ip[j].b & sn[i].b;
				res[k].c = ip[j].c & sn[i].c;
				res[k++].d = ip[j].d & sn[i].d;
			}
		/*	cout << " %%%%%%%%%%%%%% " << endl;
			for(int p=0; p<k; p++)
			{
			
				cout << res[p].a << "." << res[p].b << "." << res[p].c << "." << res[p].d << endl;
			}
				cout << " %%%%%%%%%%%%%% " << endl;
		*/
			sort(res,res+k,cmp);
			//qsort(res,k,sizeof(struct node),cmp);
		/*		cout << " ************ " << endl;
			for(int p=0; p<k; p++)
			{
			
				cout << res[p].a << "." << res[p].b << "." << res[p].c << "." << res[p].d << endl;
			}
			cout << " ************ " << endl;
		*/	
			int ans = 1;
			for(int t = 1; t<k; t++)
			{
				if(res[t].a != res[t-1].a || res[t].b != res[t-1].b || res[t].c != res[t-1].c || res[t].d != res[t-1].d)
					 ans++;
			}
			
			cout << ans << endl;
		}
		
	}
	return 0;
} </span>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读