Programming contests

Informatikai versenyfeladatok, selejtező, 2012. február 6.

February 6, 2012, 6:10 PM – February 6, 2012, 7:45 PM

I can't read it!

The Chinese writing system was developed about 4000 years ago, and it has changed relatively little since then. It consists of more than 40 thousand characters, where each character means a word or an idea. Spoken Chinese differs very much from region to region, but the written language is mostly the same. Thus writing acts as a unifying common language among the different regions.

Since over one billion people speak Chinese, it is of great practieal importance to have a program that is capable of translating Chinese text to English. We have developed such a program, but it is not working perfectly. The problem is that Chinese can be written in two different ways: either the characters are written from left to right, or they are written vertically, with the columns going from right to left. The translator program is confused by these two possibilities: the translated English text is reversed. More precisely, the words follow each other in a left to right order, as they should, but the letters in a word go from right to left. Thus instead of the text “one two three”, the program produces “eno owt eerht”. Your job is to write a program that takes this reversed text, and outputs the correct translation.

Input Specification

The input contains several blocks of test cases. Each case begins with a line containing an integer 1 ≤ n ≤ 100 000, the number of lines in this test case. This is followed by n, lines of text. The length of each line is at most 1000 characters. The only characters appearing on these lines are the letters 'a'–'z' and the space character.

The input is terminated by a block with n = 0.

Output Specification

For each test case, you have to output the n lines, with the words reversed. A word is a sequence of characters delimited by spaces, by the start of the line or by the end of the line. The spaces and new line characters have to be printed exactly as they appeared in the input.

Sample Input

  1. 1
  2. eno owt eerht
  3. 2
  4.  abcde
  5. aabb   cac x ab
  6. 0
download as text file

Output for Sample Input

  1. one two three
  2.  edcba
  3. bbaa   cac x ba
download as text file
University of Debrecen; Faculty of Informatics; v. 09/30/2024