#K61237. Reorder Sentences
Reorder Sentences
Reorder Sentences
You are given multiple sentences. Each sentence is a string containing words separated by spaces. Your task is to reorder the words in each sentence in lexicographical order. The input ends with a sentence that is exactly "END"; this sentence should not be processed.
Example:
Input: I am Groot Groot am I I am hero END</p>Output: Groot I am Groot I am I am hero
Note: Words should be compared using standard lexicographical order (based on ASCII values). If a sentence contains multiple identical words, their order in the output should reflect the sorted order.
inputFormat
The input will be provided via standard input (stdin) and consists of multiple lines. Each line contains one sentence. The sequence of sentences is terminated by a line containing exactly "END" (without quotes), and this terminating sentence should not be processed.
outputFormat
For each sentence processed (excluding the terminating "END"), output the sentence with its words sorted in lexicographical order. Each processed sentence should be printed on a new line to standard output (stdout).
## sampleI am Groot
Groot am I
I am hero
END
Groot I am
Groot I am
I am hero
</p>