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