#K60542. Reverse Every Other Word
Reverse Every Other Word
Reverse Every Other Word
Given a sentence, reverse every other word starting from the second one. More specifically, for the input sentence composed of words separated by spaces, reverse the characters of every word in an even position while leaving the odd-positioned words unchanged. The transformation should follow the mathematical rule:
\(\text{For } i \ge 0, \text{ if } i \mod 2 = 1 \text{ then } word_i \rightarrow reverse(word_i)\)
For example, the sentence "Hello world this is a test" should be transformed into "Hello dlrow this si a tset".
inputFormat
The input is provided via standard input (stdin) as a single line containing a sentence. The sentence may be empty and is composed of words separated by spaces.
outputFormat
Output the modified sentence to standard output (stdout). The output should be the sentence after reversing every other word (i.e. words in even positions when counting from zero-based index or, equivalently, every second word starting with the second one) using the transformation described above.
## sampleHello world this is a test
Hello dlrow this si a tset