【pat】L1-039 Antique typesetting

Chinese ancients wrote characters vertically from right to left. For this question, you are asked to write a program to format a paragraph of text according to the ancient style.

Input format:

The input gives a positive integer N (<100) on the first line, which is the number of characters in each column. The second line gives a non-empty string with a length not exceeding 1000, terminated by a carriage return.

Output format:

Typesets the given string in archaic style, with N characters per column (except that the last column may have fewer than N characters).

Input sample:

Sample output:

Ideas:
1. Each column has n characters, that is, there are n rows. The length of the string divided by the number of rows is the number of columns. If there is a remainder, the number of columns is +1.
2. Open a two-dimensional array to save, first initialize it as a space (!!!, because the last column (viewed from right to left) may not be full).
3. Then, the first letter of the string is placed in the last column of the first row. After the last column is full, the penultimate column starts to be arranged, and a nested loop is implemented. Outside j=col-->1, Inside i=1-->n, starting from the subscript of the string is 0, if the subscript value is less than the length of the string, put it in the array.
4. After finishing, output this two-dimensional array from left to right.

AC:

Guess you like

Origin blog.csdn.net/m0_62504956/article/details/128632769