Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- number_of_presents = int(input())
- size_of_matrix = int(input())
- nice_kids = []
- santa_current_position = (0, 0)
- matrix = []
- for row in range(size_of_matrix):
- lanes = [x for x in input().split()]
- matrix.append(lanes)
- for col in range(size_of_matrix):
- if matrix[row][col] == 'V':
- nice_kids.append([row, col])
- elif matrix[row][col] == 'S':
- santa_current_position = (row, col)
- directions = {
- 'up': (-1, 0),
- 'down': (1, 0),
- 'right': (0, 1),
- 'left': (0, -1)
- }
- happy_kids = len(nice_kids)
- while True:
- if number_of_presents <= 0:
- break
- commands = input()
- if commands == 'Christmas morning':
- break
- next_row = santa_current_position[0] + directions[commands][0]
- next_col = santa_current_position[1] + directions[commands][1]
- if 0 <= next_row < size_of_matrix and 0 <= next_col < size_of_matrix:
- matrix[santa_current_position[0]][santa_current_position[1]] = '-'
- if matrix[next_row][next_col] == '-' or matrix[next_row][next_col] == 'X':
- santa_current_position = (next_row, next_col)
- continue
- elif matrix[next_row][next_col] == 'V':
- number_of_presents -= 1
- nice_kids.remove([next_row, next_col])
- elif matrix[next_row][
- next_col] == 'C':
- if matrix[next_row - 1][next_col] == 'V' or matrix[next_row - 1][next_col] == 'X':
- number_of_presents -= 1
- nice_kids.remove([next_row - 1, next_col]) if matrix[next_row - 1][next_col] == 'V' else ''
- matrix[next_row - 1][next_col] = '-'
- if matrix[next_row + 1][next_col] == 'V' or matrix[next_row + 1][next_col] == 'X':
- number_of_presents -= 1
- nice_kids.remove([next_row + 1, next_col]) if matrix[next_row + 1][next_col] == 'V' else ''
- matrix[next_row + 1][next_col] = '-'
- if matrix[next_row][next_col - 1] == 'V' or matrix[next_row][next_col - 1] == 'X':
- number_of_presents -= 1
- nice_kids.remove([next_row, next_col - 1]) if matrix[next_row][next_col - 1] == 'V' else ''
- matrix[next_row][next_col - 1] = '-'
- if matrix[next_row][next_col + 1] == 'V' or matrix[next_row][next_col + 1] == 'X':
- number_of_presents -= 1
- nice_kids.remove([next_row, next_col + 1]) if matrix[next_row][next_col + 1] == 'V' else ''
- matrix[next_row][next_col + 1] = '-'
- santa_current_position = (next_row, next_col)
- matrix[santa_current_position[0]][santa_current_position[1]] = 'S'
- if nice_kids and number_of_presents == 0:
- print("Santa ran out of presents!")
- [print(" ".join(element)) for element in matrix]
- print(f"Good job, Santa! {happy_kids} happy nice kid/s.") \
- if not nice_kids else print(f"No presents for {len(nice_kids)} nice kid/s.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement