|
|||
Sentence SpiralAlthough the English language is a left-to-right, top-to-bottom language, this is not the only way to orient text on a page. Hebrew, for example, is right-to-left, top-to-bottom, and traditional Chinese is top-to-bottom, right-to-left. Well, in the mythical country of Yooperland, text is arranged in a counterclockwise spiral starting from the lower-left corner of a square grid and ending in a central position. For example, the phrase “SECOND WEEK OF DEER CAMP!” can be written in a 5 × 5 grid as follows:
For this problem, you will take strings of text written in the standard English left-to-right format and print them out in the square spiral format of Yooperland. Input SpecificationYou will be given a series of test cases, followed by a line containing a single 0. The first line of each test case will consist of a single decimal integer N between 4 and 10 inclusive. The next line will contain a string containing no more than N2 characters. There may or may not be one or more additional newline characters between test cases or between a test case and the terminating 0. Output SpecificationThe test cases should appear in the output in the order in which they appeared in the input. For each test case, you should print an N × N grid of letters, each line terminated by a newline character. If the input string is smaller than N2 characters in length, the string should be padded on the right with spaces to N2 characters before being placed in the grid. Aside from the trailing spaces and the spaces which were in the input string originally, no extra spaces should appear in the output. Each test case should be followed by an empty line. Sample Input
Output for Sample Input
Original Problem |
|||
University of Debrecen; Faculty of Informatics; v. 09/30/2024 |