fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.HashMap;
  4. import java.util.Scanner;
  5.  
  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)
  11. {
  12. // your code goes here
  13. Scanner scan=new Scanner(System.in);
  14. int n=scan.nextInt();
  15. int []a=new int[n];
  16. HashMap<Integer,Integer> map=new HashMap<>();
  17. for(int i=0;i<a.length;i++)
  18. {
  19. a[i]=scan.nextInt();
  20. int g=map.getOrDefault(a[i],0);
  21. map.put(a[i],g+1);
  22. }
  23.  
  24.  
  25. int q=scan.nextInt();
  26.  
  27. for(int i=0;i<q;i++)
  28. {
  29. int query=scan.nextInt();
  30. int count =map.getOrDefault(query,0);
  31. System.out.println(count);
  32. }
  33. }
  34. }
Success #stdin #stdout 0.12s 54572KB
stdin
4
1 2 2 3
2
2
3
stdout
2
1