fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main() {
  6. int n; // array size
  7. cin >> n;
  8. vector<int> arr(n);
  9.  
  10. for (int i = 0; i < n; i++) {
  11. cin >> arr[i];
  12. }
  13.  
  14. // Getting frequency of each query in that array.
  15. int q; // number of queries
  16. cin >> q;
  17. for (int i = 0; i < q; i++) {
  18. int query;
  19. cin >> query;
  20. int count = 0;
  21. for (int j = 0; j < n; j++) {
  22. if (arr[j] == query) count++;
  23. }
  24. cout << count << endl;
  25. }
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0.01s 5312KB
stdin
5
2
2
4
5
7
3
2
5
6
stdout
2
1
0