fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Scanner sc = new Scanner(System.in);
  13. int n = sc.nextInt();
  14. int [] arr = new int[n];
  15. for(int i = 0; i < n; i++){
  16. arr[i] = sc.nextInt();
  17. }
  18. int q = sc.nextInt();
  19. for(int i = 0; i < q; i++){
  20.  
  21. int query = sc.nextInt();
  22. int count = 0;
  23.  
  24. for(int j = 0; j < n ; j++){
  25. if(arr[j] == query){
  26. count++;
  27. }
  28. }
  29. System.out.println("count of query " + query + " is " + count );
  30. }
  31.  
  32. }
  33. }
Success #stdin #stdout 0.16s 58912KB
stdin
5
1 1 2 2 3
3
1
2
5
stdout
count of query 1 is 2
count of query 2 is 2
count of query 5 is 0