To and FroTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 5478 Accepted Submission (s): 3788
Problem Descriptionmo and Larry have devised a by encrypting messages. They first decide secretly on the number of columns and write the message (Letters only) down the columns, padding with ex TRA 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 be five columns, Mo would write do Wn
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 has used any let ter.
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 is encrypted as
Toioynnkpheleaigshareconhtomesnlewx
Your job is to recover for Larry the original message (along with any extra padding letters) from the encrypted one.
Inputthere'll be multiple input sets. Input for each set would consist of the lines. The first line would contain an integer in the range 2. . . indicating the number of columns used. The next line was a string of up to $ lower case letters. The last input set was followed by a line containing a single 0, indicating end of input.
Outputeach input set should generate one line of output, giving the original plaintext message, with no spaces.
Sample Input5 toioynnkpheleaigshareconhtomesnlewx 3 TTYOHHIENEESIAABSS 0
Sample outputtheresnoplacelikehomeonasnowynightx Thisistheeasyoneab
Sourceeast Central North America 2004
RECOMMENDIGNATIUS.L | We have carefully selected several similar problems for you:1196 1073 1161 1039 1020//ac:
1#include <stdio.h>2#include <string.h>3 Charstr[ About][ About], ch[ About] ;4 intMain ()5 {6 intN;7 while(~SCANF ("%d", &N), N)8 {9scanf"%s", ch);Ten intLen =strlen (CH); One intL = len/n;//number of rows; A - if(len% n! =0)//The remainder is not 0, the number of rows is +1; -L + =1 ; the - intK, I, J; -K =0 ; - for(i=0; I < L; i++) + { - if(i%2==0)//rotate the string into a two-dimensional array; + { A for(j=0; j<n; J + +) at { -STR[I][J] =Ch[k]; -k++ ; - } - } - Else in { - for(j=n-1; j>=0; j--) to { +STR[I][J] =Ch[k]; -k++ ; the } * } $ /*if (k = = len)Panax Notoginseng Break ;*/ - } the for(j=0; j<n; J + +)//column unchanged, row changes the output; + { A for(i=0; i<l; i++) theprintf"%c", Str[i][j]); + } -printf"\ n") ; $ } $ return 0 ; -}
Hangzhou Electric 1200--to and Fro