Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # https://judge.softuni.org/Contests/Practice/Index/3306#1
- current_position, empty_position, last_position, workshop = "Y", ".", "x", []
- rows, cols = map(int, input().split(", "))
- collected_items = {"D": [0, 0], "G": [0, 0], "C": [0, 0]}
- for row in range(rows):
- line = input().split()
- workshop.append(line)
- for col, cell in enumerate(line):
- if cell in collected_items:
- collected_items[cell][0] += 1
- start_row, start_col = -1, -1
- for row in range(rows):
- for col in range(cols):
- if workshop[row][col] == current_position:
- start_row, start_col = row, col
- break
- if start_row != -1:
- break
- while True:
- distination = input().strip()
- if distination.lower() == 'end':
- break
- direction, steps = distination.split('-')
- steps = int(steps)
- for _ in range(steps):
- new_row, new_col = start_row, start_col
- if direction == "up":
- new_row -= 1
- elif direction == "down":
- new_row += 1
- elif direction == "left":
- new_col -= 1
- elif direction == "right":
- new_col += 1
- if new_row < 0:
- new_row = rows - 1
- elif new_row >= rows:
- new_row = 0
- if new_col < 0:
- new_col = cols - 1
- elif new_col >= cols:
- new_col = 0
- if (new_row, new_col) != (start_row, start_col):
- workshop[start_row][start_col] = last_position
- new_cell = workshop[new_row][new_col]
- if new_cell in collected_items:
- collected_items[new_cell][1] += 1
- workshop[new_row][new_col] = empty_position
- workshop[new_row][new_col] = current_position
- start_row, start_col = new_row, new_col
- all_items_collected = True
- for key in collected_items:
- if collected_items[key][0] != collected_items[key][1]:
- all_items_collected = False
- break
- if all_items_collected:
- break
- if all_items_collected:
- break
- if all_items_collected:
- print("\nMerry Christmas!")
- print("You've collected:")
- print(f"- {collected_items['D'][1]} Christmas decorations")
- print(f"- {collected_items['G'][1]} Gifts")
- print(f"- {collected_items['C'][1]} Cookies")
- for line in workshop:
- print(" ".join(line))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement