Skip to content

Instantly share code, notes, and snippets.

@nomarlo
Created December 7, 2015 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nomarlo/d4a82cf7a03944b1fdcd to your computer and use it in GitHub Desktop.
Save nomarlo/d4a82cf7a03944b1fdcd to your computer and use it in GitHub Desktop.
/**
Considerar que ninguno de los dos tiene más de una copia del mismo disco.
Solucón usando un set, se podría hacer de igual forma con un array lo que reduciria las consultas
de Log a constante.
**/
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <sstream>
#include <map>
#include <set>
using namespace std;
std::set<int>::iterator it;
set <int> B;
int n,m,aux,r;
long long int res;
int main(){
scanf("%d %d",&n,&m);
while(n||m){
r=0;
for(int i=0;i<n;i++){
scanf("%d",&aux);
B.insert(aux);
}
for(int i=0;i<m;i++){
scanf("%d",&aux);
it=B.find(aux);
if(it!=B.end()){
r++;
B.erase(it);
}
}
if(!B.empty())
B.clear();
printf("%d\n",r);
scanf("%d %d",&n,&m);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment