Connection Status:
Competition Arena > PiCalculator
SRM 246 · 2005-06-09 · by Andrew_Lazarev · String Manipulation
Class Name: PiCalculator
Return Type: String
Method Name: calculate
Arg Types: (int)
Problem Statement

Problem Statement

The problem statement contains the unicode symbols.

You are developing a new software calculator. A very important feature is the auto-placing of the ? value by one click. The only problem is that you don't know the required precision. That's why you decided to write a program that can return ? with any reasonable precision.

You are given an int precision. You should return the ? value with exactly precision digits after the decimal point. The last digit(s) should be rounded according to the standard rounding rules (less than five round down, more than or equal to five round up).

Notes

  • ? equals 3.141592653589793238462643383279...

Constraints

  • precision will be between 1 and 25, inclusive.
Examples
0)
2
Returns: "3.14"
1)
4
Returns: "3.1416"

The value should be rounded.

2)
12
Returns: "3.141592653590"

Be careful with rounding.

3)
1
Returns: "3.1"
4)
3
Returns: "3.142"

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

Coding Area

Language: C++17 · define a public class PiCalculator with a public method string calculate(int precision) · 32 test cases · 2 s / 256 MB per case

Submitting as anonymous