Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Python Advanced Retake Exam - 14 April 2021
- # https://judge.softuni.org/Contests/Practice/Index/2828#0
- # 01. Pizza Orders
- # 02. Darts
- # 03. Flights
- ---------------------------------------------------------------------------------------
- # 01. Pizza Orders
- from collections import deque
- orders = deque([int(p) for p in input().split(', ') if int(p) in range(1, 11)])
- workers = deque([int(w) for w in input().split(', ')])
- total_pizzas = sum(orders)
- while True:
- if not orders or not workers:
- break
- first_order = orders[0]
- last_worker = workers[-1]
- if first_order <= last_worker:
- orders.popleft()
- else:
- orders[0] = first_order - last_worker
- workers.pop()
- if not orders:
- print(f'All orders are successfully completed!')
- print(f'Total pizzas made: {total_pizzas}')
- print(f'Employees: {", ".join(str(emp) for emp in workers)}')
- else:
- print(f'Not all orders are completed.')
- print(f'Orders left: {", ".join(str(order) for order in orders)}')
- ---------------------------------------------------------------------------------------
- # 02. Darts
- #1 OLD VERSION !
- def is_inside_func(r, c):
- return 0 <= r < 7 and 0 <= c < 7
- name1, name2 = input().split(', ')
- matrix = []
- player1_turns = 0
- player2_turns = 0
- player1_points = 501
- player2_points = 501
- for row_index in range(7):
- matrix.append(input().split())
- counter_shoots = 0
- while True:
- points = 0
- counter_shoots += 1
- row, col = eval(input())
- if counter_shoots % 2 != 0:
- player1_turns += 1
- else:
- player2_turns += 1
- if is_inside_func(row, col):
- if matrix[row][col] not in ['D', 'T', 'B']:
- points = int(matrix[row][col])
- else:
- if matrix[row][col] == 'B':
- if counter_shoots % 2 != 0:
- print(f'{name1} won the game with {player1_turns} throws!')
- else:
- print(f'{name2} won the game with {player2_turns} throws!')
- break
- points += int(matrix[row][6]) + int(matrix[row][0]) + int(matrix[6][col]) + int(matrix[0][col])
- if matrix[row][col] == 'T':
- points *= 3
- elif matrix[row][col] == 'D':
- points *= 2
- if counter_shoots % 2 != 0:
- player1_points -= points
- if player1_points <= 0:
- print(f'{name1} won the game with {player1_turns} throws!')
- break
- else:
- player2_points -= points
- if player2_points <= 0:
- print(f'{name2} won the game with {player2_turns} throws!')
- break
- ===================================================================================================================
- # 02. Darts
- # 2 NEW VERSION !
- from collections import deque
- def is_inside(r, c):
- return 0 <= r < SIZE and 0 <= c < SIZE
- def calculate_points_func(player, letter, r, c):
- current_sum = int(matrix[r][0]) + int(matrix[r][6]) +\
- int(matrix[0][c]) + int(matrix[6][c])
- if letter == 'T':
- current_sum *= 3
- elif letter == 'D':
- current_sum *= 2
- scores[player] -= current_sum
- SIZE = 7
- matrix = []
- names = input().split(', ')
- players = deque([names[0], names[1]])
- for _ in range(SIZE):
- matrix.append(input().split())
- scores = {names[0]: 501, names[1]: 501}
- throws = {names[0]: 0, names[1]: 0}
- while True:
- command = input()
- if command == '':
- break
- current_player = players[0]
- row, col = eval(command)
- throws[current_player] += 1
- if is_inside(row, col):
- current_shot = matrix[row][col]
- if current_shot == 'B':
- print(f'{current_player} won the game with {throws[current_player]} throws!')
- break
- if not current_shot.isalpha():
- scores[current_player] -= int(current_shot)
- else:
- calculate_points_func(current_player, current_shot, row, col)
- if scores[current_player] <= 0:
- print(f'{current_player} won the game with {throws[current_player]} throws!')
- break
- players.rotate()
- ---------------------------------------------------------------------------------------
- # 03. Flights
- def flights(*args):
- my_flights = {}
- counter = 0
- for index, destination in enumerate(args[::2]):
- counter += 1
- if destination == 'Finish':
- break
- if destination not in my_flights.keys():
- my_flights[destination] = 0
- my_flights[destination] += args[index + counter]
- return my_flights
- ---------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement