Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- m = int(input())
- n = int(input())
- matrix = [[x for x in input().split()] for _ in range(n)]
- nice_count = 0
- def count_nice(data):
- nice = 0
- for el in data:
- nice += el.count('V')
- return nice
- def moves(c, row, col):
- global matrix
- matrix[row][col] = '-'
- if c == 'up' and row-1 >= 0:
- position = [row-1, col]
- elif c == 'down' and row+1 < len(matrix):
- position = [row+1, col]
- elif c == 'right' and col+1 < len(matrix):
- position = [row, col+1]
- elif c == 'left' and col-1 >= 0:
- position = [row, col-1]
- else:
- position = [row, col]
- return position[0], position[1]
- def actions(rw, cw):
- global matrix
- global nice_count
- global m
- global all_nice
- if matrix[rw][cw] == 'V':
- matrix[rw][cw] = '-'
- nice_count += 1
- m -= 1
- if m == 0 and nice_count < all_nice:
- return "Santa ran out of presents!"
- elif nice_count == all_nice:
- return 'Done'
- elif matrix[rw][cw] == 'X':
- matrix[rw][cw] = '-'
- elif matrix[rw][cw] == 'C':
- if (matrix[rw-1][cw] == 'V' or matrix[rw-1][cw] == 'X') and m > 0:
- if matrix[rw-1][cw] == 'V':
- nice_count += 1
- matrix[rw-1][cw] = '-'
- m -= 1
- if (matrix[rw+1][cw] == 'V' or matrix[rw+1][cw] == 'X') and m > 0:
- if matrix[rw+1][cw] == 'V':
- nice_count += 1
- matrix[rw+1][cw] = '-'
- m -= 1
- if (matrix[rw][cw-1] == 'V' or matrix[rw][cw-1] == 'X') and m > 0:
- if matrix[rw][cw-1] == 'V':
- nice_count += 1
- matrix[rw][cw-1] = '-'
- m -= 1
- if (matrix[rw][cw+1] == 'V' or matrix[rw][cw+1] == 'X') and m > 0:
- if matrix[rw][cw+1] == 'V':
- nice_count += 1
- matrix[rw][cw+1] = '-'
- m -= 1
- if m == 0 and nice_count < all_nice:
- return "Santa ran out of presents!"
- return
- all_nice = count_nice(matrix)
- start = []
- for i in range(len(matrix)):
- for j in range(len(matrix)):
- if matrix[i][j] == 'S':
- start = [i, j]
- while True:
- command = input()
- if command == 'Christmas morning':
- break
- start = moves(command, start[0], start[1])
- message = actions(start[0], start[1])
- matrix[start[0]][start[1]] = 'S'
- if message:
- break
- if nice_count < all_nice and m == 0:
- print('Santa ran out of presents!')
- for element in matrix:
- print(' '.join(element))
- if nice_count == all_nice:
- print(f"Good job, Santa! {nice_count} happy nice kid/s.")
- else:
- left = all_nice - nice_count
- print(f'No presents for {left} nice kid/s.')
Add Comment
Please, Sign In to add comment