Advertisement
GeorgiLukanov87

Python Advanced Retake Exam - 14 April 2021

Sep 13th, 2022 (edited)
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.76 KB | None | 0 0
  1. # Python Advanced Retake Exam - 14 April 2021
  2.  
  3. # https://judge.softuni.org/Contests/Practice/Index/2828#0
  4.  
  5. # 01. Pizza Orders
  6. # 02. Darts
  7. # 03. Flights
  8.  
  9. ---------------------------------------------------------------------------------------
  10.  
  11. # 01. Pizza Orders
  12.  
  13.  
  14. from collections import deque
  15.  
  16. orders = deque([int(p) for p in input().split(', ') if int(p) in range(1, 11)])
  17. workers = deque([int(w) for w in input().split(', ')])
  18. total_pizzas = sum(orders)
  19.  
  20. while True:
  21.     if not orders or not workers:
  22.         break
  23.        
  24.     first_order = orders[0]
  25.     last_worker = workers[-1]
  26.  
  27.     if first_order <= last_worker:
  28.         orders.popleft()
  29.     else:
  30.         orders[0] = first_order - last_worker
  31.  
  32.     workers.pop()
  33.  
  34. if not orders:
  35.     print(f'All orders are successfully completed!')
  36.     print(f'Total pizzas made: {total_pizzas}')
  37.     print(f'Employees: {", ".join(str(emp) for emp in workers)}')
  38. else:
  39.     print(f'Not all orders are completed.')
  40.     print(f'Orders left: {", ".join(str(order) for order in orders)}')
  41.  
  42.    
  43. ---------------------------------------------------------------------------------------
  44.  
  45. # 02. Darts
  46.  
  47. #1 OLD VERSION !
  48.  
  49. def is_inside_func(r, c):
  50.     return 0 <= r < 7 and 0 <= c < 7
  51.  
  52.  
  53. name1, name2 = input().split(', ')
  54. matrix = []
  55. player1_turns = 0
  56. player2_turns = 0
  57. player1_points = 501
  58. player2_points = 501
  59.  
  60. for row_index in range(7):
  61.     matrix.append(input().split())
  62.  
  63. counter_shoots = 0
  64. while True:
  65.     points = 0
  66.     counter_shoots += 1
  67.     row, col = eval(input())
  68.  
  69.     if counter_shoots % 2 != 0:
  70.         player1_turns += 1
  71.     else:
  72.         player2_turns += 1
  73.  
  74.     if is_inside_func(row, col):
  75.         if matrix[row][col] not in ['D', 'T', 'B']:
  76.             points = int(matrix[row][col])
  77.         else:
  78.             if matrix[row][col] == 'B':
  79.                 if counter_shoots % 2 != 0:
  80.                     print(f'{name1} won the game with {player1_turns} throws!')
  81.                 else:
  82.                     print(f'{name2} won the game with {player2_turns} throws!')
  83.                 break
  84.  
  85.             points += int(matrix[row][6]) + int(matrix[row][0]) + int(matrix[6][col]) + int(matrix[0][col])
  86.  
  87.             if matrix[row][col] == 'T':
  88.                 points *= 3
  89.             elif matrix[row][col] == 'D':
  90.                 points *= 2
  91.  
  92.     if counter_shoots % 2 != 0:
  93.         player1_points -= points
  94.         if player1_points <= 0:
  95.             print(f'{name1} won the game with {player1_turns} throws!')
  96.             break
  97.     else:
  98.         player2_points -= points
  99.         if player2_points <= 0:
  100.             print(f'{name2} won the game with {player2_turns} throws!')
  101.             break
  102. ===================================================================================================================
  103. # 02. Darts
  104. # 2 NEW VERSION !
  105.  
  106. from collections import deque
  107.  
  108.  
  109. def is_inside(r, c):
  110.     return 0 <= r < SIZE and 0 <= c < SIZE
  111.  
  112.  
  113. def calculate_points_func(player, letter, r, c):
  114.     current_sum = int(matrix[r][0]) + int(matrix[r][6]) +\
  115.                   int(matrix[0][c]) + int(matrix[6][c])
  116.     if letter == 'T':
  117.         current_sum *= 3
  118.     elif letter == 'D':
  119.         current_sum *= 2
  120.     scores[player] -= current_sum
  121.  
  122.  
  123. SIZE = 7
  124. matrix = []
  125. names = input().split(', ')
  126. players = deque([names[0], names[1]])
  127. for _ in range(SIZE):
  128.     matrix.append(input().split())
  129.  
  130. scores = {names[0]: 501, names[1]: 501}
  131. throws = {names[0]: 0, names[1]: 0}
  132. while True:
  133.     command = input()
  134.     if command == '':
  135.         break
  136.  
  137.     current_player = players[0]
  138.     row, col = eval(command)
  139.     throws[current_player] += 1
  140.  
  141.     if is_inside(row, col):
  142.         current_shot = matrix[row][col]
  143.         if current_shot == 'B':
  144.             print(f'{current_player} won the game with {throws[current_player]} throws!')
  145.             break
  146.  
  147.         if not current_shot.isalpha():
  148.             scores[current_player] -= int(current_shot)
  149.  
  150.         else:
  151.             calculate_points_func(current_player, current_shot, row, col)
  152.             if scores[current_player] <= 0:
  153.                 print(f'{current_player} won the game with {throws[current_player]} throws!')
  154.                 break
  155.  
  156.     players.rotate()
  157.  
  158.  
  159.            
  160. ---------------------------------------------------------------------------------------
  161.  
  162. # 03. Flights
  163.  
  164.  
  165. def flights(*args):
  166.     my_flights = {}
  167.     counter = 0
  168.     for index, destination in enumerate(args[::2]):
  169.         counter += 1
  170.         if destination == 'Finish':
  171.             break
  172.  
  173.         if destination not in my_flights.keys():
  174.             my_flights[destination] = 0
  175.         my_flights[destination] += args[index + counter]
  176.  
  177.     return my_flights
  178.  
  179.  
  180. ---------------------------------------------------------------------------------------
  181.  
  182.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement