1357 Number Format
Submit solution
Points:
100
Time limit:
1.0s
Memory limit:
32M
Problem types
Allowed languages
C, C++, Java, Python
Description
You are a developer for a financial computer system. Users of the system often operate with large numbers, so it's important that numbers be formatted in an easy-to-read manner. You are given a number containing the internal representation of a non-negative number. This number will contain only digits, along with an optional decimal separator represented by a comma (','). Format the number as follows:
- If the number contains a decimal separator, replace the decimal separator with a period ('.').
- Divide the integer part of the number into groups of three consecutive digits, from right to left. Depending on the number of digits, the left-most group might contain 1 or 2 or 3 digits. Insert a single space (' ') between each pair of consecutive groups. (The integer part of the number is the part of the number to the left of the decimal separator if one exists, or the entire number if there is no decimal separator.) For example, "1234567,890" would be formatted as "1 234 567.89" and "1024" would be formatted as "1 024". If insignificant leading or trailing zeroes exist in the number, they must be deleted. For example, "00003,000000" would be formatted "3".
Input
The input contains multiple test cases. For each test case, it only contains a large number (up to 1000 digits).
Output
Output the formatted version of the given number.
Sample
Input
1234567,890
1024
00003,1234000
Output
1 234 567.89
1 024
3.1234
Source: cryboy
Comments