#K68882. Reverse Each Word in a Sentence
Reverse Each Word in a Sentence
Reverse Each Word in a Sentence
You are given T sentences. For each sentence, you need to reverse every word individually while keeping the word order unchanged.
For example, if the sentence is hello world, the output should be olleh dlrow.
Note: A word is defined as a maximal substring consisting of non-space characters.
Mathematically, if a word is represented as \(w = w_1w_2 \cdots w_k\), then its reversal is \(w_k \cdots w_2w_1\). The order of words remains the same in the sentence.
inputFormat
The input is taken from standard input stdin
and is formatted as follows:
- The first line contains an integer T, the number of sentences.
- The following T lines each contain a sentence.
outputFormat
For each input sentence, output the sentence where every word is reversed, preserving the original word order. Each output sentence should be printed on a new line to standard output stdout
.
1
hello world
olleh dlrow
</p>