15,905,607 members

See more:

For exp we have this sequence of numbers:

10 25 50 50

p(10) = 25% and 10!= p(10) =25 so false

p(25) = 25% and 25 == 25 so true

p(50) = 50% and 50 == p(50) =50 true

the number of true is 2 so p(true) is 75%

i want to print 75% (the number of true, i mean count the proba when the number equal its probability of apperance in the sequence )

here is my essaie :

**What I have tried:**

10 25 50 50

p(10) = 25% and 10!= p(10) =25 so false

p(25) = 25% and 25 == 25 so true

p(50) = 50% and 50 == p(50) =50 true

the number of true is 2 so p(true) is 75%

i want to print 75% (the number of true, i mean count the proba when the number equal its probability of apperance in the sequence )

here is my essaie :

Java

import java.util.*; import java.io.*; import java.math.*; /** * Auto-generated code below aims at helping you parse * the standard input according to the problem statement. **/ class proba { public static void main(String args[]) { Scanner in = new Scanner(System.in); int s=0; int p=1; int ss=0; int N = in.nextInt(); List<Integer> l = new ArrayList<>(); for (int i = 0; i < N; i++) { int v = in.nextInt(); l.add(v); } ListIterator<Integer> it = l.listIterator(); while(it.hasNext()){ Integer i = it.next(); while(it.hasNext()){ if(it.equals(i)) s++; } p=(s/N)*100; if (p == i) ss++; } System.out.print((ss/N)*100); } }

Comments

To compute the probability of every number you must count its occurrences in the list. The algorithm is simpler provided the list is ordered.

Permalink

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject,
20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8
+1 (416) 849-8900

What is the problem?

What does it do that you didn't expect, or not do that you did?

What help do you need?

That explains everything.