fork download
  1. #include <iostream>
  2. #include<vector>
  3. using namespace std;
  4.  
  5. int main() {
  6. int n;
  7. cin >> n;
  8.  
  9. vector<int> array(n);
  10.  
  11. for(int i=0; i<n; i++) {
  12. cin >> array[i];
  13. }
  14.  
  15. int q;
  16. cin >> q;
  17.  
  18. for(int i=0; i<q; i++) {
  19. int query;
  20. cin >> query;
  21.  
  22. int count = 0;
  23.  
  24. for(int j=0; j<n; j++) {
  25. if(array[j] == query) {
  26. count++;
  27. }
  28. }
  29. cout << query << " : " << count << endl;
  30. }
  31. }
Success #stdin #stdout 0s 5316KB
stdin
7
1
1
2
2
2
3
3
3
1
2
3
stdout
1 : 2
2 : 3
3 : 2