天天看點

sicily 1007 To and Fro (基礎題)

連結:http://soj.me/show_problem.php?pid=1007

description

mo and larry have devised a way of encrypting messages. they first decide secretly on the number of columns and write the message (letters only) down the columns, padding with extra random letters so as to make a rectangular array of letters. for example, if

the message is "there‘s no place like home on a snowy night" and there are five columns, mo would write down 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 in lower case. in this

example, mo used the character `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 in each row, alternating left-to-right and right-to-left. so, the above would be

encrypted as toioynnkpheleaigshareconhtomesnlewx your job is to recover for larry the original message (along with any extra padding letters) from the encrypted one.

input

there will be multiple input sets. input for each set will consist of two lines. the first line will contain an integer in the range 2 . ..20 indicating the number of columns used. the next line is a string of up to 200 lower case letters. the last input set

is followed by a line containing a single 0, indicating end of input.

output

each input set should generate one line of output, giving the original plaintext message, with no spaces.

sample input

sicily 1007 To and Fro (基礎題)

 copy sample input to clipboard

sample output

解題思路:

按照加密的方式還原回去就可以了;

代碼如下:

繼續閱讀