Home
About
Resume
Projects
Links
Blog
Back to Contents
# Google Code Jam Qualification Round Q1 - Punched Cards #### Declaration This post is released after the end of the Qualification Round of Code Jam. #### Question Please refer to: [Code Jam Official Site](https://codingcompetitions.withgoogle.com/codejam/round/0000000000876ff1/0000000000a4621b) #### Solution ##### Idea 1. Create a 2D array to store the output drawing. - - May reduce the overhead time of calling `print` separately. - - Easier to manipulate the output drawing. 2. Print out the array. ##### Code 1\. Define a function to `Create a 2D array to store the output drawing`: ```python def create_card(n_row,n_col): result_card = [] #declare card in "." for dummy in range(2*n_row+1): result_card.append(["."]*(2*n_col+1)) #replace "." by desired symbol for i in range(2*n_row+1): for j in range(2*n_col+1): if i < 2 and j < 2: continue if i%2 == 0 and j%2 == 0: result_card[i][j] = "+" if i%2 == 0 and j%2 != 0: result_card[i][j] = "-" if i%2 != 0 and j%2 == 0: result_card[i][j] = "|" return result_card ``` 2\. Define a function to `Print out the array`: ```python def print_card(card_array): print("\n".join(["".join(row) for row in card_array])) ``` 3\. Necessary IO: ```python T = int(input()) if T < 1 or T > 81: print("Error Input") exit() for i in range(T): line_input = input() R, C = [int(i) for i in line_input.split(" ")] if ( R < 2 or R > 10 ) or ( C < 2 or C > 10 ): print("Error Input") exit() print(f"Case #{i+1}:") print_card(create_card(R,C)) ```
Previous Post:
Google Code Jam Qualification Round Q2
Next Post:
Python Manipulate PDF
Loading