20: Repeat and repeat
20: Repeat
- View
- Submit
- Statistics
- Question
-
Total time limit:
-
1000 ms
-
Memory limit:
-
65536kB
-
Description
-
Mo and Larry invented an information encryption method. They first determine the number of columns, then fill in the information (including only letters) from top to bottom, and add some random letters at the end to make it a complete letter matrix. For example, if the information is "There's no place like home on a snowy night" and There are five columns, Mo will write:
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 is only filled in lowercase letters. In this example, Mo fills the information with the letter "x" to make it a complete matrix. Of course, he can use any letter.
Mo writes the information based on this matrix: first write the first row from left to right, then write the second row from right to left, and then write the third row from left to right ...... This allows you to write letters from top to bottom to form a new string. In this case, the information in the example is encrypted as: toioynnkpheleaig1_conhtomesnlewx.
Your job is to help Larry Restore original information (including filled letters) from the encrypted information ).
-
Input
-
The first row contains an integer (ranging from 2 to 20), indicating the number of columns used.
The second line is a string of no more than 200 characters.
-
Output
-
A row, that is, the original information.
-
Sample Input
-
5toioynnkpheleaigshareconhtomesnlewx
-
Sample output
-
theresnoplacelikehomeonasnowynightx
-
Source
-
East Central North America 2004
-
1 # include <iostream> 2 # include <cstdio> 3 # include <cmath> 4 # include <cstring> 5 using namespace std; 6 char a [1001]; 7 int now = 0; 8 char B [101] [101]; 9 int main () {10 int n, m; 11 cin> n; 12 scanf ("% s", & a); 13 int l = strlen (a); 14 int hang = l/n; 15 int I = 1; 16 int j = 1; 17 int fx = 1; // 1 right 2 left 18 while (I * j! = (Hang + 1) * n) 19 {20 if (fx = 1) 21 {22 B [I] [j] = a [now]; 23 now ++; 24 j ++; 25} 26 else if (fx = 2) 27 {28 B [I] [j] = a [now]; 29 now ++; 30 j --; 31} 32 if (j = n + 1) 33 {34 I ++; 35 j --; 36 fx = 2; 37} 38 if (j = 0 & I! = 1) 39 {40 I ++; 41 j ++; 42 fx = 1; 43} 44 46} 47 B [I] [j] = a [now]; 48/* for (int I = 1; I <= hang; I ++) 49 {50 for (int j = 1; j <= n; j ++) 51 {52 B [I] [j] = a [now]; 53 now ++; 54} 55} */56/* for (int I = 1; I <= hang; I ++) 57 {58 for (int j = 1; j <= n; j ++) 59 cout <B [I] [j]; 60 cout <endl; 61} */62 I = 1, j = 1; 63 int tot = 0; 64 while (tot! = Hang * n) 65 {66 tot ++; 67 cout <B [I] [j]; 68 I ++; 69 if (I = hang) 70 {71 tot ++; 72 cout <B [I] [j]; 73 I = 1; 74 j ++; 75} 76} 77 78 return 0; 79}