Advertisement
roronoa

probabilites

Jun 18th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. class Solution {
  4.  
  5.     public static void main(String args[]) {
  6.         Scanner in = new Scanner(System.in);
  7.         int N = in.nextInt();
  8.         int[] values = new int[N];
  9.         boolean[] probs = new boolean[N];
  10.         for (int i = 0; i < N; i++) {
  11.             values[i] = in.nextInt();
  12.             probs[i] = false;
  13.         }
  14.         for(int i = 0; i < values.length; i++)
  15.             if(p(values, values[i]) == values[i])
  16.                 probs[i] = true;
  17.         int nb = 0;
  18.         for(boolean b : probs)
  19.             if(b)
  20.                 nb++;
  21.         System.out.print(nb*100/N);
  22.     }
  23.     public static int p(int[] tab, int x)
  24.     {
  25.         int c = 0;
  26.         for(int i : tab)
  27.             if(i == x)
  28.                 c++;
  29.         return c*100/tab.length;
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement