CCC '01 S2 - Spirals (Exact Version)

View as PDF

Submit solution

Points: 7
Time limit: 1.0s
Memory limit: 16M

Problem type
Canadian Computing Competition: 2001 Stage 1, Junior #4, Senior #2

A spiral of numbers can start and end with any positive integers less than 100. Write a program which will repeatedly accept two positive integers x and y as input, and output a list of numbers from x to y 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

The first line will contain a positive integer T, the number of test cases. You may assume T \le 100.

Each of the next T lines will contain two integers, x and y. You may assume 1 \le x \le y < 100.

Output

Output T 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 veridct.

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


  • 1
    Mackrel  commented on May 26, 2020, 1:54 p.m.

    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 testings seem to be successful, so I really don't know what part of my code doesn't fit with the format.


  • 1
    Dr_Dabbidy  commented on Dec. 20, 2019, 4:27 p.m. edited

    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: 1
    2 3 You still need to put the spaces above the 3 to make each row have the smae 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 eahc other row. If you are using rstrip() or something similar, make sure you are not removing the spaces that you needed for padding.


  • -1
    risperss  commented on Dec. 19, 2019, 11:49 a.m. edited

    Fixed.


  • 0
    ScriptKitty  commented on July 16, 2018, 5:58 p.m.

    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


    • 7
      xxsc  commented on Nov. 11, 2018, 11:30 a.m.

      73 72 71 70 69 68 67 66 65

      74 43 42 41 40 39 38 37 64 99

      75 44 21 20 19 18 17 36 63 98

      76 45 22 07 06 05 16 35 62 97

      77 46 23 08 01 04 15 34 61 96

      78 47 24 09 02 03 14 33 60 95

      79 48 25 10 11 12 13 32 59 94

      80 49 26 27 28 29 30 31 58 93

      81 50 51 52 53 54 55 56 57 92

      82 83 84 85 86 87 88 89 90 91

      Note: I have blank lines between all of the rows, and I have a 0 in front of every single-digit number.


      • 0
        Dr_Dabbidy  commented on Dec. 20, 2019, 4:44 p.m. edited

        73 72 71 70 69 68 67 66 65
        74 43 42 41 40 39 38 37 64 99 75 44 21 20 19 18 17 36 63 98 76 45 22 7 6 5 16 35 62 97 77 46 23 8 1 4 15 34 61 96 78 47 24 9 2 3 14 33 60 95 79 48 25 10 11 12 13 32 59 94 80 49 26 27 28 29 30 31 58 93 81 50 51 52 53 54 55 56 57 92 82 83 84 85 86 87 88 89 90 91

        The above is the correct format. EDIT SORRY THE SPACING IS ALL MESSED UP


      • 0
        Dan13llljws  commented on Dec. 12, 2019, 8:10 a.m. edited

        Im sure i did what the output specification told, but i just keep getting presentation error, can someone help? Also, output specification says that we need to use space to fill not 0’s?


        • 0
          Subway_Man  commented on April 24, 2020, 7:56 p.m.

          If a number is not present in a given location, spaces should be printed as a replacement.

          The comments are giving conflicting answers to the problem statement.