Arne Saknussemm
Time limit1sMemory limit128 MB
Reverse a described scrambling procedure that pads, reverses, and writes a message column by column into a table, given its row fragments, to recover the original text.
- Level
Medium5 of 10
- Topics
- String, Simulation, Implementation
- Solved
- No attempts yet
Problem
Following the account of Jules Verne, a scrambled message written by the medieval alchemist Arne Saknussemm and deciphered by professor Lidenbrock started the incredible journey to the center of the Earth. The scrambling procedure used by Arne is similar to the one described below.
1. Take a non-empty message that contains letters of the English alphabet, digits, commas, dots, quotes (i.e. '), spaces, and line breaks, and whose last character is not a space. For example, consider the following message, whose translation reads "In Sneffels's crater descend brave traveler, and touch the center of the Earth".
In Sneffels craterem descende audas
viator, et terrestre centrum attinges.
2. Choose an integer and append trailing spaces to so that the length of the resulting message is the least multiple of . For and the message above, where (including the 8 spaces and the line break that contains), two trailing spaces are added, yielding with .
3. Replace every space in by the character _ (underscore), replace every line break in by \ (backslash), and then reverse the message. In our case:
__.segnitta_murtnec_ertserret_te_,rotaiv\sadua_ednecsed_meretarc_sleffenS_nI
4. Write the message produced in step 3 into a table with rows and columns. The writing is done column by column. For the example, the message is written into a table with rows and columns as follows:
5. The strings of characters corresponding to the rows of the table are the fragments of the scrambled message. The 4 fragments of Arne's message from step 1 are:
_etmneet_t\udsmt_fS _gtuerr_,asaneeasf_
.narctrtria_edrrlen si_t_seeovdec_ecenI
Write a program that deciphers non-empty messages scrambled as described. The length of a message, before scrambling, is at most characters, including spaces and line breaks.
Input
The program input is read from a text file in which each data set corresponds to one scrambled message. A data set starts with an integer , the number of fragments of the scrambled message, and continues with strings of characters denoting the fragments, in the order in which they appear in the table from step 4 of the scrambling procedure. The input data are separated by whitespace and terminate at end of file.
Output
The deciphered message must be printed to standard output, starting at the beginning of a line, and must be followed by an empty line, as shown in the input/output sample below.