Advertisement
pacho_the_python

north_pole

Jul 21st, 2022
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.87 KB | None | 0 0
  1. rows, cols = list(map(int, input().split(", ")))
  2.  
  3. matrix = []
  4. decorations = 0
  5. gifts = 0
  6. cookies = 0
  7. items = 0
  8. condition = False
  9. for row in range(rows):
  10.     matrix.append(list(input().split()))
  11.  
  12. player_rol = 0
  13. player_col = 0
  14.  
  15. for i in range(rows):
  16.     for j in range(cols):
  17.         if matrix[i][j] == "Y":
  18.             player_rol, player_col = i, j
  19.         if matrix[i][j] in "CDG":
  20.             items += 1
  21. command = input().split("-")
  22. while True:
  23.     if command[0] == "End":
  24.         break
  25.     if command[0] == "right":
  26.         step = int(command[1])
  27.         while True:
  28.             if items == 0:
  29.                 condition = True
  30.                 break
  31.             if step == 0:
  32.                 break
  33.             matrix[player_rol][player_col] = "x"
  34.             player_col += 1
  35.             if player_col == cols:
  36.                 player_col = 0
  37.             if matrix[player_rol][player_col] == "D":
  38.                 decorations += 1
  39.                 items -= 1
  40.             elif matrix[player_rol][player_col] == "G":
  41.                 gifts += 1
  42.                 items -= 1
  43.             elif matrix[player_rol][player_col] == "C":
  44.                 cookies += 1
  45.                 items -= 1
  46.             matrix[player_rol][player_col] = "Y"
  47.  
  48.             step -= 1
  49.  
  50.     elif command[0] == "left":
  51.         step = int(command[1])
  52.         while True:
  53.             if items == 0:
  54.                 condition = True
  55.                 break
  56.             if step == 0:
  57.                 break
  58.             matrix[player_rol][player_col] = "x"
  59.             player_col -= 1
  60.             if player_col < 0:
  61.                 player_col = cols - 1
  62.             if matrix[player_rol][player_col] == "D":
  63.                 decorations += 1
  64.                 items -= 1
  65.             elif matrix[player_rol][player_col] == "G":
  66.                 gifts += 1
  67.                 items -= 1
  68.             elif matrix[player_rol][player_col] == "C":
  69.                 cookies += 1
  70.                 items -= 1
  71.             matrix[player_rol][player_col] = "Y"
  72.             step -= 1
  73.  
  74.     elif command[0] == "down":
  75.         step = int(command[1])
  76.         while True:
  77.             if items == 0:
  78.                 condition = True
  79.                 break
  80.             if step == 0:
  81.                 break
  82.             matrix[player_rol][player_col] = "x"
  83.             player_rol += 1
  84.             if player_rol == rows:
  85.                 player_rol = 0
  86.             if matrix[player_rol][player_col] == "D":
  87.                 decorations += 1
  88.                 items -= 1
  89.             elif matrix[player_rol][player_col] == "G":
  90.                 gifts += 1
  91.                 items -= 1
  92.             elif matrix[player_rol][player_col] == "C":
  93.                 cookies += 1
  94.                 items -= 1
  95.             matrix[player_rol][player_col] = "Y"
  96.             step -= 1
  97.  
  98.     elif command[0] == "up":
  99.         step = int(command[1])
  100.         while True:
  101.             if items == 0:
  102.                 condition = True
  103.                 break
  104.             if step == 0:
  105.                 break
  106.             matrix[player_rol][player_col] = "x"
  107.             player_rol -= 1
  108.             if player_rol < 0:
  109.                 player_rol = rows - 1
  110.             if matrix[player_rol][player_col] == "D":
  111.                 decorations += 1
  112.                 items -= 1
  113.             elif matrix[player_rol][player_col] == "G":
  114.                 gifts += 1
  115.                 items -= 1
  116.             elif matrix[player_rol][player_col] == "C":
  117.                 cookies += 1
  118.                 items -= 1
  119.             matrix[player_rol][player_col] = "Y"
  120.             step -= 1
  121.     if condition:
  122.         break
  123.     command = input().split("-")
  124.  
  125. if items == 0:
  126.     print("Merry Christmas!")
  127. print("You've collected:")
  128. print(f"- {decorations} Christmas decorations")
  129. print(f"- {gifts} Gifts")
  130. print(f"- {cookies} Cookies")
  131.  
  132. for z in matrix:
  133.     print(*z, sep=" ")
  134.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement