Canadian Computing Competition: 2001 Stage 1, Junior #4, Senior #2
A spiral of numbers can start and end with any positive integers less than . Write a program which will repeatedly accept two positive integers and as input, and output a list of numbers from to inclusive, shown in a spiral. You may assume that the end value is greater than or equal to the start value.
A spiral starts with the first number in the centre. The next number appears immediately below the first number. The spiral continues with the numbers increasing in a counter-clockwise direction until the last number is printed.
Input Specification
The first line will contain a positive integer , the number of test cases. You may assume .
Each of the next lines will contain two integers, and . You may assume .
Output Specification
Output spirals. Between every pair of adjacent spirals, there should be exactly one blank line.
For every spiral, each line should have the same number of characters printed. There must be at least one line with no leading whitespace and no trailing whitespace. Adjacent columns must be separated by exactly one space. Numbers in a column must be right-aligned and take up exactly the number of characters equal to the length of the largest integer in the column. Numbers that do not take up the full width should be padded with spaces. If a number is not present in a given location, spaces should be printed as a replacement.
Note: Unlike the original version of this problem, this version provides an output specification that must be matched exactly. Failure to adhere exactly to the specification will result in a Wrong Answer verdict.
Sample Input 1
1
10 27
Sample Output 1
27 26
16 15 14 25
17 10 13 24
18 11 12 23
19 20 21 22
Sample Input 2
2
1 2
1 1
Sample Output 2
1
2
1
Comments
I love spirals!!!
For people that are struggling with presentation errors:
The length of every output line should be the same, accomplished by padding with whitespace either at the front or at the end.
The formatting stuff can make you crazy.
I keep getting Presentation Errors, and I have absolutely no idea where I'm going wrong. The only test I'm passing successfully is the last one. All my personal tests seem to be successful, so I really don't know what part of my code doesn't fit with the format.
Edit: I finally figured it out! There must be a newline in-between each spiral, but NOT at the beginning or end of the entire output. Furthermore, the rules for whether a number requires padding or not depends on the highest number of digits within each individual column, not the entire spiral.
For example, a spiral from 5-10 would look like this:
As you can see, the first column requires padding on its single-digit numbers because there is a double-digit number within the column (10), whereas the second column only has single-digit numbers, so padding is required to not exist.
Hope this helps to sort out any confusion for future individuals!
There are several possibilities:
For columns with single digits, they are supposed to have single padding to be as compact as possible.
Make sure all lines have exactly the same number of character count, aka padding subject to the compact constraints (see first point).
There is supposed to be a newline at the very end last numerical output line.
I hope it helps!
I am getting whitespace errors. I think the issue at this point is that they want a very specific formatting. One hard thing to do is when you have something as follows:
You still need to put the spaces above the 3 to make each row have the same number of characters.
EDIT: I got it! One main thing I wasn't looking at was making sure each row has extra spaces/as many characters as each other row. If you are using rstrip() or something similar, make sure you are not removing the spaces that you needed for padding.
I cannot seem to figure out the correct format for the answer. Can somebody please help and give some more examples? The correct matrix for 1 to 99 would be very beneficial!
Thanks
The above is the correct format.