#K79462. Format Number with Commas

    ID: 35314 Type: Default 1000ms 256MiB

Format Number with Commas

Format Number with Commas

You are given a string representing a non-negative integer that may contain leading zeros. Your task is to format this string by inserting commas as thousands separators. All unnecessary leading zeros should be removed, unless the number is zero, in which case it should remain as "0".

Details:

  • If the input string has leading zeros (e.g. "001234567"), they should be removed.
  • Commas must be inserted from the right side into groups of three digits.
  • If the resulting number is empty after removing zeros, output "0".

Examples:

  • Input: "1234567" → Output: "1,234,567"
  • Input: "001234567" → Output: "1,234,567"
  • Input: "1000" → Output: "1,000"
  • Input: "0001000" → Output: "1,000"
  • Input: "0" → Output: "0"

inputFormat

A single line containing a non-negative integer as a string (possibly with leading zeros) is provided via standard input.

outputFormat

Output the formatted number with commas as thousands separators to standard output.## sample

1234567
1,234,567