#C1688. Sort Words by Length

    ID: 44920 Type: Default 1000ms 256MiB

Sort Words by Length

Sort Words by Length

Given an input string that may contain leading, trailing, or multiple spaces between words, your task is to sort the words in ascending order based on their lengths. If two words have the same length, they should appear in the same order as in the original string.

Details:

  • The input string may have extra spaces; however, words are separated by one or more spaces.
  • If the string is empty or contains only spaces, the output should be an empty string.
  • The relative order of words with the same length must be preserved.

Note: In all our test cases, the input is provided from standard input (stdin) and the result should be printed to standard output (stdout).

inputFormat

The input consists of a single line containing a string. The string may include leading, trailing, or multiple spaces between words.

outputFormat

Output a single line containing the words sorted in ascending order by their lengths, separated by a single space.

## sample
Hello
Hello

</p>