Practice
Resources
Contests
Online IDE
New
Free Mock
Scaler
Practice
Improve your coding skills with our resources
Contests
Compete in popular contests with top coders
Scaler
Explore Offerings by SCALER

Begin your success journey!

Sign Up using
Full name *
Email *
Password *

By creating an account, I acknowledge that I have read and agree to InterviewBit’s Terms and Privacy Policy .

Welcome back!

Log In using
Email *
Password *

BigDecimal

Problem Description

The BigDecimal class provides operations on double numbers for arithmetic, scale handling, rounding, comparison, format conversion and hashing. It can handle very large and very small floating-point numbers with great precision but compensating with the time complexity a bit.

A BigDecimal consists of a random precision integer unscaled value and a 32-bit integer scale. If greater than or equal to zero, the scale is the number of digits to the right of the decimal point. If less than zero, the unscaled value of the number is multiplied by 10^(-scale).

Syntax:

Declaration

double a, b;  
BigDecimal A, B;

Initialization:

a = 5.4;  
b = 2.3;  
A = BigDecimal.valueOf(5.4);  
B = BigDecimal.valueOf(2.3);

If you are given a String representation of a double number then you can initialize in the following manner:

A = new BigDecimal(“5.4”);  
B = new BigDecimal(“1238126387123.1234”);

Extraction of value from BigDecimal:

// value should be in limit of double x  
double x = A.doubleValue();

// To get string representation of BigDecimal A  
String z = A.toString();

Comparison:

if (a < b) {} // For primitive double  
if (A.compareTo(B) < 0) {} // For BigDecimal

Actually compareTo returns -1(less than), 0(Equal), 1(greater than) according to values.

For equality we can also use:

if (A.equals(B)) {} // A is equal to B  

To read more about BigDecimal and its methods Click Here.

Task:

Given an array, s, of n real number strings, sort them in descending order — but wait, there's more! Each number must be printed in the exact same format as it was read from stdin, meaning that .1  is printed as .1, and 0.1 is printed as 0.1. If two numbers represent numerically equivalent values (e.g. .1 is equivalent to 0.1), then they must be listed in the same order as they were received as input).

Complete the code in the editor below. You must rearrange array s's elements according to the instructions above.

Problem Constraints

1 <= n <= 200

Each si has atmost 300 digits.



Input Format

The first line consists of a single integer,n, denoting the number of integer strings.

Each line i of the n subsequent lines contains a real number denoting the value of si .



Output Format

Pre-written code in the editor will print the contents of array s to stdout. You are only responsible for reordering the array's elements.



Example Input

Sample Input:

 9
 -100
 50
 0
 56.6
 90
 0.12
 .12
 02.34
 000.000



Example Output

Sample Output:

 90
 56.6
 50
 02.34
 0.12
 .12
 0
 000.000
 -100



Start solving BigDecimal on Interview Code Editor
Hints
  • Complete Solution

Discussion


Loading...
Click here to start solving coding interview questions
Free Mock Assessment
Fill up the details for personalised experience.
All fields are mandatory
Current Employer *
Enter company name *
Graduation Year *
Select an option *
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
Phone Number *
OTP will be sent to this number for verification
+1 *
+1
Change Number
Phone Number *
OTP will be sent to this number for verification
+1 *
+1
Change Number
Graduation Year *
Graduation Year *
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
*Enter the expected year of graduation if you're student
Current Employer *
Company Name *
Please verify your phone number
Edit
Resend OTP
By clicking on Start Test, I agree to be contacted by Scaler in the future.
Already have an account? Log in
Free Mock Assessment
Instructions from Interviewbit
Start Test