#C12437. Formatting Numbers with Commas

    ID: 41864 Type: Default 1000ms 256MiB

Formatting Numbers with Commas

Formatting Numbers with Commas

Given an integer N, format the number by inserting commas as thousand separators. For example, if N = 1000, the output should be 1,000; if N = -123456789, the output should be -123,456,789. The number can be positive, negative, or zero. Use proper formatting to ensure that groups of three digits are separated by commas. In mathematical terms, if N is the given integer, its decimal representation should be formatted as:

\(\text{formatted}(N) = \begin{cases}\text{'-'} + f(|N|) & \text{if } N < 0,\\ f(N) & \text{if } N \ge 0,\end{cases}\)

where \(f(N)\) represents the number with commas inserted at every thousand.

inputFormat

The input consists of a single line containing an integer N, which can be negative, zero, or positive.

outputFormat

Output the string representation of the integer with commas as thousand separators.## sample

1000
1,000