Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = int(input())
- matrix = [[x for x in input().split()] for _ in range(n)]
- # print(matrix)
- collection = []
- stolen = 0
- def collect(m, r, c, l):
- if 0 <= r < len(m) and 0 <= c < len(m[r]) and m[r][c] != '-':
- l.append(m[r][c])
- matrix[r][c] = '-'
- def steal(d, r, c, m):
- s = 0
- if 0 <= r < len(m) and 0 <= c < len(matrix[r]) and m[r][c] != '-':
- s += 1
- m[r][c] = '-'
- for i in range(3):
- if d == 'up' and 0 <= r-1 < len(m) and 0 <= c < len(m[r-1]):
- r -= 1
- if m[r][c] != '-':
- m[r][c] = '-'
- s += 1
- elif d == 'down' and 0 <= r+1 < len(m) and 0 <= c < len(m[r+1]):
- r += 1
- if m[r][c] != '-':
- m[r][c] = '-'
- s += 1
- elif d == 'left' and 0 <= c-1 < len(m[r]):
- c -= 1
- if m[r][c] != '-':
- m[r][c] = '-'
- s += 1
- elif d == 'right' and 0 <= c+1 < len(m[r]):
- c += 1
- if m[r][c] != '-':
- m[r][c] = '-'
- s += 1
- else:
- return s
- return s
- while True:
- data = input()
- if data == 'Sunset':
- break
- command = data.split()
- if command[0] == 'Collect':
- collect(matrix, int(command[1]), int(command[2]), collection)
- elif command[0] == 'Steal':
- stolen += steal(command[3], int(command[1]), int(command[2]), matrix)
- for line in matrix:
- print(' '.join(line))
- if collection:
- print(f'Collected seashells: {len(collection)} -> {", ".join(collection)}')
- else:
- print('Collected seashells: 0')
- print(f"Stolen seashells: {stolen}")
Advertisement
Add Comment
Please, Sign In to add comment