Connection Status:
Competition Arena > ThreeDigits
SRM 789 · 2020-08-28 · by square1001 · Math
Class Name: ThreeDigits
Return Type: String
Method Name: calculate
Arg Types: (int, int, int)
Problem Statement

Problem Statement

Find the last three digits before the decimal point and the first three digits after the decimal point in the number XY / Z.

Return your answer formatted as a String. The String must always include the decimal point and exactly three digits after the decimal point. If the number has fewer than three digits before the decimal point, only include those digits, do not pad the number with zeros.

Notes

  • Do not perform any rounding, just output the correct digits in the required places. E.g., if the exact number is 123.4567, the correct output is "123.456", not "123.457".
  • For numbers with finite decimal expansions we are using the more natural form where all the following digits are zeros. For example, if the exact number is 123.4, only "123.400" is a correct answer, "123.399" (as a prefix of 123.9999999...) will be rejected.

Constraints

  • X will be between 0 and 1000000000 (1 billion).
  • Y will be between 0 and 1000000000 (1 billion).
  • Z will be between 1 and 1000000 (1 million).
  • Either X or Y will be non-zero.
Examples
0)
3
5
7
Returns: "34.714"

In this example, since the value of XY / Z = 243 / 7 = 34.7142857..., you should return "34.714".

1)
4
7
32
Returns: "512.000"

In this example, since the value of XY / Z = 16384 / 32 = 512.0000000..., you should return "512.000".

2)
3
2
36
Returns: "0.250"

In this example, since the value of XY / Z = 9 / 36 = 0.2500000..., you should return "0.250". Note that the "0" before the decimal point is mandatory, the return value ".250" will be rejected.

3)
7
4
47
Returns: "51.085"

In this example, since the value of XY / Z = 2401 / 47 = 51.0851063..., you should return "51.085".

4)
13
6
479
Returns: "076.845"

13^6 / 479 = 10076.84551148..., so the correct answer is "076.845". Note that this number has more than three digits before its decimal point, so the return value must start "076" and not just "76".

5)
1234
56789
123456
Returns: "133.942"

The value of 123456789 / 123456 has 175,548 digits before the decimal point. The number begins 4028022093412... and around its decimal point we have the digits ...7339915133.9429756350...

6)
999999999
128
1000000
Returns: "000.000"

In this example, both of the last three digits before the decimal point and the first three digits after the decimal point are "000", even though the value is not an integer.

Submissions are judged against all 119 archived test cases, of which 7 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class ThreeDigits with a public method string calculate(int X, int Y, int Z) · 119 test cases · 2 s / 256 MB per case

Submitting as anonymous