Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Python Advanced Exam - 14 February 2021
- #
- # https://judge.softuni.org/Contests/Practice/Index/2812#2
- # 01. Fireworks Show
- # 02. Collecting Coins
- # 03. Cupcake Shop
- ----------------------------------------------------------------------------------------------------------
- # 01. Fireworks Show
- # NEW VERSION
- from collections import deque
- effects = deque([int(x) for x in input().split(', ')])
- power = deque([int(x) for x in input().split(', ')])
- bombs = {"Palm Fireworks": 0, "Willow Fireworks": 0, "Crossette Fireworks": 0, }
- success = False
- while effects and power:
- not_mixed = True
- first_effect = effects[0]
- last_power = power[-1]
- if first_effect <= 0 or last_power <= 0:
- if first_effect <= 0 and effects:
- effects.popleft()
- if last_power <= 0 and power:
- power.pop()
- continue
- result = first_effect + last_power
- if result % 3 == 0 and result % 5 != 0:
- bombs['Palm Fireworks'] += 1
- elif result % 5 == 0 and result % 3 != 0:
- bombs['Willow Fireworks'] += 1
- elif result % 3 == 0 and result % 5 == 0:
- bombs['Crossette Fireworks'] += 1
- else:
- effects.append(effects.popleft() - 1)
- not_mixed = False
- if not_mixed:
- effects.popleft()
- power.pop()
- if bombs["Palm Fireworks"] >= 3 and bombs["Willow Fireworks"] >= 3 and bombs["Crossette Fireworks"] >= 3:
- success = True
- break
- if success:
- print("Congrats! You made the perfect firework show!")
- else:
- print("Sorry. You can't make the perfect firework show.")
- if effects:
- print(f'Firework Effects left: {", ".join(str(x) for x in effects)}')
- if power:
- print(f'Explosive Power left: {", ".join(str(x) for x in power)}')
- for bomb, count in bombs.items():
- print(f'{bomb}: {count}')
- ===========================================================================================================
- # 01. Fireworks Show
- # OLD VERSION
- from collections import deque
- effect = deque([int(x) for x in input().split(', ') if int(x) > 0])
- power = deque([int(x) for x in input().split(', ') if int(x) > 0])
- palm_firework = 0
- willow_firework = 0
- crossette_firework = 0
- success = False
- while True:
- if not effect or not power:
- break
- first_effect = effect[0]
- last_power = power[-1]
- result = first_effect + last_power
- if result % 3 == 0 and result % 5 != 0:
- palm_firework += 1
- effect.popleft()
- power.pop()
- elif result % 5 == 0 and result % 3 != 0:
- willow_firework += 1
- effect.popleft()
- power.pop()
- elif result % 3 == 0 and result % 5 == 0:
- crossette_firework += 1
- effect.popleft()
- power.pop()
- else:
- removed_effect = effect.popleft()
- removed_effect -= 1
- if removed_effect > 0:
- effect.append(removed_effect)
- if palm_firework >= 3 and willow_firework >= 3 and crossette_firework >= 3:
- success = True
- break
- if success:
- print('Congrats! You made the perfect firework show!')
- else:
- print("Sorry. You can't make the perfect firework show.")
- if effect:
- print(f'Firework Effects left: {", ".join(str(e) for e in effect)}')
- if power:
- print(f'Explosive Power left: {", ".join(str(p) for p in power)}')
- print(f'Palm Fireworks: {palm_firework}')
- print(f'Willow Fireworks: {willow_firework}')
- print(f'Crossette Fireworks: {crossette_firework}')
- ----------------------------------------------------------------------------------------------------------
- # 02. Collecting Coins
- # NEW VERSION
- def validate_step(r, c):
- if r >= SIZE:
- r = 0
- elif r < 0:
- r = (SIZE - 1)
- if c >= SIZE:
- c = 0
- elif c < 0:
- c = (SIZE - 1)
- return r, c
- def get_next_position(direction, r, c):
- if direction == 'left':
- return validate_step(r, c - 1)
- elif direction == 'right':
- return validate_step(r, c + 1)
- elif direction == 'up':
- return validate_step(r - 1, c)
- elif direction == 'down':
- return validate_step(r + 1, c)
- SIZE = int(input())
- matrix = []
- row, col = 0, 0
- for row_index in range(SIZE):
- matrix.append(input().split())
- for col_index in range(SIZE):
- if matrix[row_index][col_index] == 'P':
- row, col = row_index, col_index
- points = []
- path = [[row, col]]
- while True:
- command = input()
- if command == "":
- break
- if command not in ['up', 'down', 'left', 'right']:
- continue
- row, col = get_next_position(command, row, col)
- current_step = matrix[row][col]
- path.append([row, col])
- if current_step == 'X':
- print(f"Game over! You've collected {sum(points) // 2} coins.")
- break
- if not current_step.isalpha():
- points.append(int(current_step))
- matrix[row][col] = '0'
- if sum(points) >= 100:
- print(f"You won! You've collected {sum(points)} coins.")
- break
- print('Your path:')
- for step in path:
- print(step)
- =============================================================================================================
- # 02. Collecting Coins
- # OLD VERSION
- import math
- def is_inside(some_row, some_col): # validating if cell is inside the matrix.
- return 0 <= some_row < size and 0 <= some_col < size
- def get_next_position_func(direction, row, col):
- if direction == 'up':
- return row - 1, col
- elif direction == 'down':
- return row + 1, col
- elif direction == 'left':
- return row, col - 1
- elif direction == 'right':
- return row, col + 1
- size = int(input())
- p_row = 0
- p_col = 0
- matrix = []
- for row_index in range(size):
- matrix.append(input().split())
- for col_index in range(size):
- if matrix[row_index][col_index] == 'P':
- p_row = row_index
- p_col = col_index
- wall_hit = False
- coins = 0
- path = [[p_row, p_col]]
- while True:
- command = input()
- matrix[p_row][p_col] = '0'
- next_row, next_col = get_next_position_func(command, p_row, p_col)
- path.append([next_row, next_col])
- if is_inside(next_row, next_col):
- if matrix[next_row][next_col] != 'X':
- coins += int(matrix[next_row][next_col])
- matrix[next_row][next_col] = '0'
- p_row, p_col = next_row, next_col
- else: # STEP ON X , GAME OVER
- wall_hit = True
- break
- else: # OUTSIDE THE FIELD !
- if command == 'down':
- p_row = next_row - size
- elif command == 'left':
- p_col = next_col + size
- elif command == 'up':
- p_row = next_row + size
- elif command == 'right':
- p_col = next_col - size
- path.pop(-1)
- path.append([p_row, p_col])
- if str(matrix[p_row][p_col]).isdigit() and matrix[p_row][p_col] != 'X':
- coins += int(matrix[p_row][p_col])
- matrix[p_row][p_col] = '0'
- else:
- wall_hit = True
- break
- if coins >= 100 or wall_hit:
- break
- if coins >= 100:
- print(f"You won! You've collected {coins} coins.")
- else:
- if wall_hit:
- coins /= 2
- print(f"Game over! You've collected {math.floor(coins)} coins.")
- print('Your path:')
- print(*path, sep='\n')
- ----------------------------------------------------------------------------------------------------------
- # 03. Cupcake Shop
- def stock_availability(my_list, action, *args):
- sell_products = []
- if action == 'delivery':
- for el in args:
- my_list.append(el)
- elif action == 'sell':
- if not args:
- my_list.pop(0)
- for el in args:
- sell_products.append(el)
- for el in sell_products:
- if str(el).isdigit():
- while el:
- my_list.pop(0)
- el -= 1
- else:
- while el in my_list:
- my_list.remove(el)
- return my_list
- ----------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement