fork download
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. int n = scanner.nextInt();
  7.  
  8.  
  9. int[] array = new int[n];
  10. //hashing array to store the frequencies
  11. int[] hash = new int[51];
  12.  
  13. for (int i = 0; i < n; i++) {
  14. array[i] = scanner.nextInt();
  15. //increment the count as per the index
  16. hash[array[i]]=hash[array[i]] + 1;
  17. }
  18.  
  19. //the no of queries
  20. int q = scanner.nextInt();
  21. for (int i = 0; i < q; i++) {
  22. int query = scanner.nextInt();
  23. int count = hash[query];
  24. System.out.println(count);
  25. }
  26. }
  27. }
  28.  
Success #stdin #stdout 0.15s 56588KB
stdin
7
3 3 4 4 5 1 1
3
5
1
4
stdout
1
2
2