#C13301. Reorder Words by Length
Reorder Words by Length
Reorder Words by Length
You are given a string s
that contains words separated by spaces. Your task is to reorder the words in ascending order based on their lengths.
If two words have the same length, they must remain in the same order as they appear in the original string. All characters, including special characters and punctuation, are considered as part of the words.
Note: The input is provided via standard input and the output should be printed to standard output.
For example, if you are given the input:
The quick brown fox jumps over the lazy dog
the expected output is:
The fox the dog over lazy quick brown jumps
The ordering is determined solely by the length: if we denote the length of a word w as \( |w| \), then for any two words \( a \) and \( b \), if \( |a| < |b| \), then \( a \) comes before \( b \) in the result. In the case where \( |a| = |b| \), the relative order is preserved as in the input.
inputFormat
The input consists of a single line containing the string s
. This string may contain multiple spaces between words. Read the input from standard input.
outputFormat
Output a single line containing the words of the input string reordered based on their length in ascending order, preserving the original order when lengths are equal. Write the result to standard output.
## sampleThe quick brown fox jumps over the lazy dog
The fox the dog over lazy quick brown jumps
</p>