UVA Solution 11849 CD

Solve in C++:

#include<bits/stdc++.h>
using namespace std;
int main ()
{
    int m,n,i,j,c=0;

    while(cin>>n>>m)
    {
        std::vector<int>first;
        std::vector<int>second;
        std::vector<int> v(100000000);
        std::vector<int>::iterator it;

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

        for(i=0; i<n; i++)
        {
            int x;
            cin>>x;
            first.push_back(x);
        }
        for(j=0; j<m; j++)
        {
            int y;
            cin>>y;
            second.push_back(y);
        }

        std::sort(first.begin(), first.end());
        std::sort (second.begin(),second.end());

        it=std::set_intersection (first.begin(), first.end(),second.begin(),second.end(),v.begin());

        v.resize(it-v.begin());

        std::cout << v.size()<<endl;


    }

    return 0;
}


No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.