C++TSL's Map container (sad story)

Source: Internet
Author: User

Tell a sad story!

These days are stepping up time to learn stl! The map was barely understood a little yesterday. (The premise of the story)

Today, came to the platform ready to brush about map, the teacher recommended a problem. Said to be about map. And then.. No!!

Later, Baidu. A moment of force! What the heck!

I hereby ask for advice!

IP Aggregation

Problem Description

Today's world, the network has been everywhere, the small bear because made a mistake, when the degree of the company's network administrator, he has a large number of IP list, the small bear want to know in a fixed subnet mask, how many network address. The network address is the result of the bitwise AND operation of the subnet mask and IP address, for example:

Subnet Mask: a.b.c.d

IP Address: a.b.c.d

Network address: (A&A). (b/b). (c&c). (d&d)

Input

The first line contains an integer tt t, ( 1≤T≤50) (1 \leq T \leq) (1≤t≤50) represents the number of groups of test data,

Next the TTT Group test data. Each set of test data contains several rows,

First row two positive integersN (1≤n≤1000,1≤m≤50), MN (1 \leq N \leq, 1 \leq m \leq), MN(1≤N≤1000,1≤m≤50),M. Next NNn lines, one string per line, representing an IP address,

And NextMmM rows, one string per line representing the subnet mask. Both the IP address and the subnet mask are usedA.b.c.da. B.c.dA. B. C. The form of D, where a,b,c,da,b,c,dA,B,C,d are all nonnegative integers and less than or equal to 255.

Output

For each set of test data, output two lines:

The first line of output: "Case #i:". III represents the test data for Group II I.

The second line outputs the results of the test data, and for each subnet mask in each set of data, the number of network addresses that are output under this subnet mask.

Sample Input
25 2192.168.1.0192.168.1.101192.168.2.5192.168.2.7202.14.27.235255.255.255.0255.255.0.04 2127.127.0.110.134.52.0127.0.10.110.134.0.2235.235.0.01.57.16.0
Sample Output
Case #1:32Case #2:34

Code:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <vector>
#include <map>
using namespace Std;
const int maxn=1100;
int A[MAXN];
int B[MAXN];
int C[MAXN];
int D[MAXN];
Map<long long,int> m;
int main ()
{
int t;
scanf ("%d", &t);
for (int te=1;te<=t;te++)
{
int n,m;
scanf ("%d%d", &n,&m);
for (int i=0;i<n;i++) scanf ("%d.%d.%d.%d", &a[i],&b[i],&c[i],&d[i]);
printf ("Case #%d:\n", TE);
int a,b,c,d;
int ans;
a long long temp;
for (int i=1;i<=m;i++)
{
M.clear ();
ans=0;
scanf ("%d.%d.%d.%d", &a,&b,&c,&d);
for (int j=0;j<n;j++)
{
Temp=0;
temp=temp*1000+ (A[j]&a);
temp=temp*1000+ (B[J]&AMP;B);
temp=temp*1000+ (C[J]&AMP;C);
temp=temp*1000+ (D[J]&AMP;D);
if (!m[temp])
{
ans++;
M[temp]=1;
}
}
printf ("%d\n", ans);
}
}
return 0;
}


Ask the great God to comment!!

C++TSL's Map container (sad story)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.