Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6390 Accepted Submission(s): 4389
Problem Description
Mo and Larry have devised a way of encrypting messages. They first decide secretly onthenumberofcolumnsandwritethemessage (lettersonly) downthecolumns, paddingwithextrarandomletterssoastomakearectangulararrayofletters. Forexample, ifthemessageis “There’snoplacelikehomeonasnowynight” andtherearefivecolumns, Mowouldwritedown
t o i o y
h p k n n
e l e a i
r a h s g
e c o n h
s e m o t
n l e w x
Note that Mo includes only letters and writes them all inlowercase. In this example, Mo used thecharacter ‘x’ to pad the message out to make a rectangle, although he could have used any letter.
Mo then sends the message to Larry by writing the letters ineach row, alternating left-to-rightandright-to-left. So, the above would be encrypted as
toioynnkpheleaigshareconhtomesnlewx
Your job is to recover for Larry the original message (along withany extra padding letters) fromthe encrypted one.
Input
There will be multiple input sets. Input foreachset will consist oftwolines. The firstline will contain anintegerinthe range 2. . . 20 indicating thenumberof columns used. The next line is astringof up to200lowercase letters. The last input set is followed byaline containing a single 0, indicating endofinput.
Output
Each input set should generate onelineof output, giving the original plaintext message, with no spaces.
Sample Input
5
toioynnkpheleaigshareconhtomesnlewx
3
ttyohhieneesiaabss
0
Sample Output
theresnoplacelikehomeonasnowynightx
thisistheeasyoneab
Source
East Central North America 2004
Recommend
Ignatius.L | We have carefully selected several similar problems for you: 11961073116111131256