fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t;
  5. cin>>t;
  6. for (int i = 0; i < t; i++)
  7. {
  8. int n,m,c=0;
  9. cin>>n>>m;
  10. int a[n], b[m];
  11. for(int j=0;j<n;j++)
  12. {
  13. cin>>a[j];
  14. }
  15. for(int j=0;j<m;j++)
  16. {
  17. cin>>b[j];
  18. }
  19. sort(a,a+n);
  20. sort(b,b+m);
  21.  
  22. int j=0,k=0;
  23. while(j<n && k<m)
  24. {
  25. if(a[j]==b[k])
  26. {
  27. c++;
  28. j++;
  29. }
  30. else if(a[j]<b[k])
  31. j++;
  32. else
  33. k++;
  34. }
  35. cout<<c<<endl;
  36. }
  37. }
Success #stdin #stdout 0.01s 5308KB
stdin
2
3 4
1 2 3
3 4 5 6
3 3
1 2 3
4 5 6
stdout
1
0