Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Python Advanced Exam - 25 June 2022
- # https://judge.softuni.org/Contests/Practice/Index/3515#0
- # 01. Collecting Eggs
- # 02. Exit Founder
- # 03. Shopping Cart
- ----------------------------------------------------------------------------------------------------------
- # 01. Collecting Eggs
- from collections import deque
- eggs = deque([int(x) for x in input().split(', ')]) # FIFI -> starts from index[0]
- paper = deque([int(x) for x in input().split(', ')]) # LIFO -> starts from index[-1]
- box = 0
- while True:
- if not eggs or not paper:
- break
- first_egg = eggs[0]
- last_paper = paper[-1]
- if first_egg <= 0 or first_egg == 13:
- if first_egg == 13:
- paper[0], paper[-1] = paper[-1], paper[0]
- eggs.popleft()
- continue
- result = eggs.popleft() + paper.pop()
- if result <= 50:
- box += 1
- if box > 0:
- print(f"Great! You filled {box} boxes.")
- else:
- print("Sorry! You couldn't fill any boxes!")
- if eggs:
- print(f'Eggs left: {", ".join(str(x) for x in eggs)}')
- if paper:
- print(f'Pieces of paper left: {", ".join(str(x) for x in paper)}')
- ----------------------------------------------------------------------------------------------------------
- # 02. Exit Founder
- # NEW VERSION !
- from collections import deque
- players = deque(input().split(', '))
- SIZE = 6
- matrix = []
- for _ in range(SIZE):
- matrix.append(input().split())
- wall_hit = {'Tom': 0, 'Jerry': 0}
- while True:
- current_player = players[0]
- row, col = eval(input())
- if wall_hit[current_player] >= 1:
- wall_hit[current_player] -= 1
- players.rotate()
- continue
- if matrix[row][col] == 'E':
- print(f"{current_player} found the Exit and wins the game!")
- break
- elif matrix[row][col] == 'W':
- print(f'{current_player} hits a wall and needs to rest.')
- wall_hit[current_player] += 1
- elif matrix[row][col] == 'T':
- print(f'{current_player} is out of the game! The winner is {players[1]}.')
- break
- players.rotate()
- ==========================================================================================================
- # 02. Exit Founder
- # OLD VERSION !
- player1, player2 = input().split(", ")
- matrix = []
- names = [player1, player2]
- for row_index in range(6):
- matrix.append(input().split())
- player1_skip_next_turn = False
- player2_skip_next_turn = False
- turns = 0
- while True:
- turns += 1
- if turns % 2 != 0:
- current_player = player1
- else:
- current_player = player2
- command = eval(input())
- if turns % 2 != 0 and player1_skip_next_turn:
- player1_skip_next_turn = False
- continue
- elif turns % 2 == 0 and player2_skip_next_turn:
- player2_skip_next_turn = False
- continue
- row, col = command[0], command[1]
- current_step = matrix[row][col]
- if current_step == 'E':
- print(f'{current_player} found the Exit and wins the game!')
- break
- elif current_step == 'T':
- names.remove(current_player)
- print(f'{current_player} is out of the game! The winner is {"".join(names)}.')
- break
- elif current_step == 'W':
- if turns % 2 != 0:
- player1_skip_next_turn = True
- else:
- player2_skip_next_turn = True
- print(f"{current_player} hits a wall and needs to rest.")
- ----------------------------------------------------------------------------------------------------------
- # 03. Shopping Cart
- def shopping_cart(*args):
- limit = {'Pizza': 4, 'Soup': 3, 'Dessert': 2}
- prepared = {'Pizza': [], 'Soup': [], 'Dessert': []}
- orders = 0
- for el in args:
- if el == 'Stop':
- if orders == 0:
- return 'No products in the cart!'
- break
- dish, product = el
- if product not in prepared[dish]:
- if len(prepared[dish]) < limit[dish]:
- prepared[dish] += [product]
- orders += 1
- final_print = ""
- for dish, product in sorted(prepared.items(), key=lambda x: (-len(x[1]), x[0])):
- final_print += f'{dish}:\n'
- for el in sorted(product):
- final_print += f' - {el}\n'
- return final_print
- ----------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement