Wednesday, June 7, 2017

uva problem soltuion 11849 - CD

problem link:

Discuss: In this problem you can easily do with map.you can also do it by for loop. here i am using map.in at just simply increment the number which duplicate.

try yourself before see the code



#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n,m,i,j,cnt=0,d,a;
   while(cin >>n>>m)
   {
        map <int,int>mp;
      cnt=0;

      if(n==0&&m==0)
      break;
      j=n+m;

      for(i=0;i<j;i++)
      {
         cin >>a;
         mp[a]++;
         }

for (map<int, int>::const_iterator it = mp.begin(); it != mp.end(); ++it)
      {

        d=it->second;
        if(d>1)
        cnt++;

      }
      cout <<cnt<<endl;

   }
return 0;

}

No comments:

Post a Comment