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> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- ruby-on-rails – 如何永久忽略ActiveRecord ::
- SQLite 101 for iPhone Developers: Creating an
- React Navigation--TabNavigator 详细的例子
- UBIFS设计简介 - A Brief Introduce to the Desi
- Swift 扩展(Extensions)(十四)
- ReactNative学习笔记一
- c – 多个单例实例
- 常用正则表达式大全——包括校验数字、字符、一些
- iOS 8 beta OSStatus -34018(errSecMissingEntit
- XML的两种解析方式逐行解析(SAX解析)节点解析(DO
热点阅读