Problems with 2d arrays in CCC 2018 j4 problem

122 views Asked by At

I'm working on an question that's part of the CCC(question: https://dmoj.ca/problem/ccc18s2) I have my code, but it doesnt work all the time. When I input my code into the online grader (which can be found on the linked page) I only get 3/15 marks. All the inputs I put in myself seem to work out, but the grader seems to be different.

My code:

lowest_val = []
flower=[]

n = int(input())
for i in range(0,n):
    flower.append(input().split(" "))

lowest_val.append(flower[0][0])
lowest_val.append(flower[0][n-1])
lowest_val.append(flower[n-1][0])
lowest_val.append(flower[n-1][n-1])

while True:
    if flower[0][0] == min(lowest_val):
        for row in flower:
            for i in row:
                print(i, end=" ")
            print()
        break
    flower = list(zip(*flower[::-1]))

To answer this question, I can simply check if the top left corner is the smallest corner, so flower[0][0] must be the smallest corner.

min() looks for the smallest number out of the 4 corner that I added to the list lowest_val.

I cant find a test where this fails, and that might be my biggest problem. On dmoj (the online grader) all it does is say I got part of the question wrong.

2

There are 2 answers

1
cidermole On

Here is a test case that fails with your code:

2
10 4
3 2

Can you find out why it fails?

0
itsanantk On

Figured out why my code didn't work all the time:

When I added the list corners to lowest_val the elements were all strings, not integers.

Because of that, min(lowest_val) got me the lowest value, sorted alphabetically.

To solve it I simply made all the elements integers.