fork download
  1. import java.util.*;
  2.  
  3. public class Main{
  4. public static void main(String args[]){
  5. Scanner sc=new Scanner(System.in);
  6. HashMap<Integer,Integer>hm=new HashMap<>();
  7. int n=sc.nextInt();
  8. int[] arr=new int[n];
  9. for(int i=0;i<n;i++){
  10. arr[i]=sc.nextInt();
  11. }
  12. for(int i=0;i<n;i++){
  13. hm.put(arr[i],hm.getOrDefault(arr[i],0)+1);
  14. }
  15.  
  16. int q=sc.nextInt();
  17. for(int i=0;i<q;i++){
  18. int qq=sc.nextInt();
  19. System.out.println(hm.getOrDefault(qq,0));
  20. }
  21. }
  22. }
Success #stdin #stdout 0.15s 56640KB
stdin
5
1 2 3 4 5
2 
3 9
stdout
1
0