Problem A
Amateur Coder in Mirrorland
“Ring Ring,” the alarm sounds, and you wake up, noticing that you’re late for school. You immediately grab your backpack and rush out the door. Upon walking out, you walk across the bathroom and notice a distortion in the mirror. You approach it to wipe the distortion, but upon contact, you get sucked into a rabbit hole in a blink of an eye. You open your eyes and notice that everything is the same, except that the words on the toothpaste tube is backwards. You look down and notice a note on the counter. It is apparent that the note contains words, however, they are written backwards. You try to decipher the sentences but realize it’ll take too long and that you’re already late for school. As an enthusiastic programmer, you grab your laptop out of your bag, and began constructing an algorithm to quickly reverse the backward sentences in hope of obtaining instructions on getting back to your world.
Write a program that takes text as inputs and reverse the word order as well as the letters in each word. Words that pertain to directions (Left, Right, Up, Down, In, Out) should also be converted to the corresponding word with the opposite meaning. For reference, below are the pair of words that correspond to each other. (Left, Right) (Up, Down) (In, Out)
Input
Each input file consists of one test case. Each test case begins with a string that contains only letters (lowercase and uppercase), words, and punctuation. Every word, including directional terms, which are left, right, up, down, in, and out, are reversed. Moreover, the directional terms’ meaning are also reversed, meaning that left is actually right and vice versa.
Output
Output the original string, reversed character by character, with the original directional terms replaced with their correct corresponding and opposite meaning.
Sample Input 1 | Sample Output 1 |
---|---|
.snoitcurtsni eseht wollof ,evael oT !dnalrorriM ot emocleW |
Welcome to Mirrorland! To leave, follow these instructions. |
Sample Input 2 | Sample Output 2 |
---|---|
.nedrag eht ot ni og ,sdrawretfA .tfel a ekat neht thgir nruT |
Turn left then take a right. Afterwards, go out to the garden. |