Statistics

Problem Statement for "Percents"

Problem Statement

Statistics can be misleading, even if they are technically correct. For example, if you were told that 71.43% of people polled answered "yes" to a question, the two digits after the decimal place imply high precision, and that many people must have been polled in order to arrive at that level of accuracy. However, in this example, if only 7 people were polled and 5 answered "yes", (5/7)*100 = 71.43 (rounded to the nearest hundredth of a percent). Given a percentage rounded to two decimal places, we want to determine the minimum number of people who could have been polled.

Create a class Percents with a method minSamples. This method will take a String percent that gives the percentage of people who responded "yes" to a poll, rounded to the nearest hundredth of a percent. The String percent will be of the form "xx.xx%", where each 'x' represents a digit between '0' and '9', inclusive. The method should return an int, the minimum possible number of people who could have been polled to result in that percentage.

Definition

Class:
Percents
Method:
minSamples
Parameters:
String
Returns:
int
Method signature:
int minSamples(String percent)
(be sure your method is public)

Notes

  • All percentages are rounded to the nearest hundredth of a percent. In case the difference is exactly 0.005, round up.
  • The answer will be between 1 and 10000, inclusive, as any percentage to two decimal places can be achieved with 10000 people.
  • Note that, if there were d people, then the number of people who responded "yes" must be either floor(d*percent/100) or ceil(d*percent/100).

Constraints

  • percent will contain exactly 6 characters (with leading and/or trailing zeros if necessary), and will be between "00.00%" and "99.99%", inclusive.

Examples

  1. "25.00%"

    Returns: 4

    1 out of 4 is 25.00%.

  2. "66.67%"

    Returns: 3

    2 out of 3 is 66.67%, rounded to 2 decimal places.

  3. "66.66%"

    Returns: 2858

    1905 is 66.6550034895032% of 2858. 1905/2858 is the fraction with the smallest denominator that equals 66.66 when rounded to two decimal places.

  4. "71.43%"

    Returns: 7

    This is the example from the problem statement.

  5. "00.00%"

    Returns: 1

  6. "99.99%"

    Returns: 6667

  7. "00.01%"

    Returns: 6667

  8. "09.99%"

    Returns: 671

  9. "10.00%"

    Returns: 10

  10. "10.01%"

    Returns: 669

  11. "12.90%"

    Returns: 31

  12. "99.98%"

    Returns: 4000

  13. "99.97%"

    Returns: 2858

  14. "85.54%"

    Returns: 83

  15. "27.27%"

    Returns: 11

  16. "27.52%"

    Returns: 109

  17. "56.57%"

    Returns: 99

  18. "50.05%"

    Returns: 911

  19. "50.06%"

    Returns: 771

  20. "50.07%"

    Returns: 667

  21. "55.50%"

    Returns: 191

  22. "50.50%"

    Returns: 101

  23. "00.50%"

    Returns: 199

  24. "77.77%"

    Returns: 877

  25. "77.78%"

    Returns: 9

  26. "66.66%"

    Returns: 2858

  27. "33.00%"

    Returns: 100

  28. "02.01%"

    Returns: 149

  29. "99.99%"

    Returns: 6667

  30. "00.01%"

    Returns: 6667

  31. "50.00%"

    Returns: 2

  32. "02.03%"

    Returns: 148

  33. "60.62%"

    Returns: 193

  34. "11.64%"

    Returns: 146

  35. "00.00%"

    Returns: 1

  36. "85.71%"

    Returns: 7

  37. "07.70%"

    Returns: 610

  38. "11.11%"

    Returns: 9


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: