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. int[] array = new int[n];
  9. for (int i = 0; i < n; i++) {
  10. array[i] = scanner.nextInt();
  11. }
  12.  
  13. int q = scanner.nextInt();
  14.  
  15. for (int i = 0; i < q; i++) {
  16. int query = scanner.nextInt();
  17.  
  18. int count = 0;
  19. for (int j = 0; j < n; j++) {
  20. if (array[j] == query) {
  21. count++;
  22. }
  23. }
  24. System.out.println(count);
  25. }
  26. }
  27.  
  28. }
  29.  
Success #stdin #stdout 0.11s 54596KB
stdin
5
1 2 3 4 5
2
1 3
stdout
1
1