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;
}
#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