fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int N, M;
  6. while(cin >> N >> M && N > 0 && M > 0) {
  7. unordered_set<int> cd;
  8. for(int i = 0; i < N; i++) {
  9. int tmp;
  10. cin >> tmp;
  11. cd.insert(tmp);
  12. }
  13. int count = 0;
  14. for(int i = 0; i < M; i++) {
  15. int tmp;
  16. cin >> tmp;
  17. if(cd.find(tmp) != cd.end())
  18. count++;
  19. }
  20. cout << count << endl;
  21. }
  22. return 0;
  23. }
Success #stdin #stdout 0.01s 5304KB
stdin
3 3
1
2
3
1
2
4
3 3
1
2
3
1
4
5
0 0

stdout
2
1