Words
Time limit1sMemory limit128 MB
Read lines until a line with a single #, and output each line with the characters of every word reversed, keeping spaces fixed.
- Level
Easy3 of 10
- Topics
- String, Implementation
- Solved
- No attempts yet
Problem
A nasty virus has infected my computer. Its effect is to attack all my text files and reverse every word in them. Your job is to write code that restores my text files to their original condition.
As far as the virus is concerned, a word is any sequence of characters that ends with a space or an end-of-line character. For example, the first line of one of my files was
Get ready for the New Zealand Programming Contest.
and the virus turned it into
teG ydaer rof eht weN dnalaeZ gnimmargorP .tsetnoC
Notice how the full stop stayed attached to ‘Contest’ and ended up in front of the reversed letters. Because reversing a word twice restores it, restoring a line simply means reversing each of its words again.
Input
The input consists of a number of lines, each containing up to characters. Words are separated by single spaces (never tabs, double spaces, or other characters), and a word may be of any length. The input is terminated by a line containing a single #.
Output
For each input line, output one line in which every word (as defined above) has been reversed, keeping the words in their original order and separated by the same single spaces.