Statistics

Problem Statement for "CalculatorDisplay"

Problem Statement

You have a calculator with a screen that can display up to digits digits along with a single decimal point. If the result of an operation is a number that cannot fit on the screen, the calculator will show just "E" (quotes for clarity) rather than the actual result. Note that fractional numbers less than 1.0 are always shown without the leftmost 0 (for example, ".125"). Also note that integer numbers are never shown with a decimal point, so 4 would always be shown as "4", not "4." or "4.0"." Leading zeros are never displayed (at the left of integer part or the right in the fractional part).

Given a numerator n and denominator d, return the content of the calculator's screen after dividing n by d. For example, 10005 divided by 400 is 25.0125. A 6-digit display would show "25.0125" while a 5-digit display would show "E" (all quotes for clarity only).

Definition

Class:
CalculatorDisplay
Method:
numberDivision
Parameters:
int, int, int
Returns:
String
Method signature:
String numberDivision(int digits, int n, int d)
(be sure your method is public)

Constraints

  • digits will be between 1 and 20, inclusive.
  • n will be between 0 and 1,000,000,000, inclusive.
  • d will be between 1 and 1,000,000,000, inclusive.

Examples

  1. 10

    10005

    400

    Returns: "25.0125"

    The example from the problem statement.

  2. 5

    10005

    400

    Returns: "E"

    The same result would not fit in only five digits.

  3. 10

    1

    8

    Returns: ".125"

  4. 5

    434544

    352

    Returns: "1234.5"

    Note that the decimal point does not add a position, and the result occupies all of its five digits.

  5. 20

    1

    3

    Returns: "E"

    To display the result would require an infinite number of fractional digits!

  6. 10

    1000000000

    1

    Returns: "1000000000"

  7. 9

    1000000000

    1

    Returns: "E"

  8. 1

    1000000000

    1000000000

    Returns: "1"

  9. 1

    0

    1000000000

    Returns: "0"

  10. 20

    1

    1000000000

    Returns: ".000000001"

  11. 20

    3

    1000000000

    Returns: ".000000003"

  12. 9

    3

    1000000000

    Returns: ".000000003"

  13. 10

    999999999

    1000000000

    Returns: ".999999999"

  14. 20

    465566339

    479142415

    Returns: "E"

  15. 20

    57886066

    961126156

    Returns: "E"

  16. 20

    17450740

    222702061

    Returns: "E"

  17. 20

    72282698

    19879756

    Returns: "E"

  18. 20

    58368051

    48787573

    Returns: "E"

  19. 20

    560672241

    330534376

    Returns: "E"

  20. 20

    774759233

    407464967

    Returns: "E"

  21. 20

    358347371

    336980169

    Returns: "E"

  22. 20

    266681054

    180434859

    Returns: "E"

  23. 20

    449507901

    64381965

    Returns: "E"

  24. 20

    66920523

    671014631

    Returns: "E"

  25. 20

    29219487

    701702729

    Returns: "E"

  26. 20

    83586259

    944283356

    Returns: "E"

  27. 20

    927271031

    778374505

    Returns: "E"

  28. 20

    524827736

    582236637

    Returns: "E"

  29. 20

    61379048

    807107663

    Returns: "E"

  30. 20

    620750169

    990394076

    Returns: "E"

  31. 20

    65612487

    971781471

    Returns: "E"

  32. 20

    991661224

    638200911

    Returns: "E"

  33. 20

    539504833

    137895186

    Returns: "E"

  34. 10

    8454795

    901844800

    Returns: ".009375"

  35. 20

    307483187

    635421875

    Returns: ".483904"

  36. 20

    78658538

    212720000

    Returns: ".369775"

  37. 20

    369763636

    566145280

    Returns: ".653125"

  38. 20

    81260964

    866783616

    Returns: ".09375"

  39. 20

    186664307

    198579050

    Returns: ".94"

  40. 20

    46242558

    83772750

    Returns: ".552"

  41. 20

    5106794

    77000000

    Returns: ".066322"

  42. 20

    193946298

    2769000

    Returns: "70.042"

  43. 20

    469687830

    1104

    Returns: "425441.875"

  44. 20

    563285871

    117725000

    Returns: "4.78476"

  45. 20

    305253155

    32

    Returns: "9539161.09375"

  46. 20

    628554643

    100000

    Returns: "6285.54643"

  47. 20

    61225992

    2

    Returns: "30612996"

  48. 20

    502236268

    166303400

    Returns: "3.02"

  49. 20

    82964460

    375000

    Returns: "221.23856"

  50. 20

    898175151

    5868

    Returns: "153063.25"

  51. 20

    129755301

    441645000

    Returns: ".2938"

  52. 20

    416382499

    203125000

    Returns: "2.049883072"

  53. 20

    191407

    625000

    Returns: ".3062512"

  54. 20

    361281258

    277908660

    Returns: "1.3"

  55. 20

    292369980

    120

    Returns: "2436416.5"

  56. 20

    871243107

    192750000

    Returns: "4.520068"

  57. 20

    905588065

    652000000

    Returns: "1.38893875"

  58. 20

    942903306

    1562500

    Returns: "603.45811584"

  59. 20

    675584109

    265247000

    Returns: "2.547"

  60. 20

    990295695

    96

    Returns: "10315580.15625"

  61. 20

    105896624

    19660000

    Returns: "5.3864"

  62. 9

    999999999

    1000000000

    Returns: ".999999999"

  63. 8

    999999999

    1000000000

    Returns: "E"

  64. 13

    0

    987654321

    Returns: "0"

    The result is just zero. Note that the decimal point is not shown if the result is an integer.

  65. 9

    999999999

    1000000000

    Returns: ".999999999"

  66. 1

    500000000

    1000000000

    Returns: ".5"

  67. 1

    1

    1

    Returns: "1"

  68. 20

    999999999

    1000000000

    Returns: ".999999999"


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: