Advertisement
GeorgiLukanov87

Python Advanced Retake Exam - 18 August 2022

Sep 19th, 2022 (edited)
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.10 KB | None | 0 0
  1. # Python Advanced Retake Exam - 18 August 2022
  2.  
  3. # https://judge.softuni.org/Contests/Practice/Index/3534#2
  4.  
  5. # 01. Stewards
  6. # 02. CRUD
  7. # 03. Song Creator
  8.  
  9. ------------------------------------------------------------------------------------------
  10.  
  11. # 01. Stewards
  12.  
  13.  
  14. from collections import deque
  15.  
  16. all_seats = input().split(', ')
  17. first_nums = deque([int(x) for x in input().split(', ')])
  18. second_nums = deque([int(x) for x in input().split(', ')])
  19.  
  20. rotations = 0
  21. seat_matches = []
  22.  
  23. while True:
  24.     first_first = first_nums[0]
  25.     last_second = second_nums[-1]
  26.     rotations += 1
  27.     sum_result = first_first + last_second
  28.     searched_letter = chr(sum_result)
  29.     for seat in all_seats:
  30.         if str(first_first) + searched_letter == seat or str(last_second) + searched_letter == seat:
  31.             if seat not in seat_matches:
  32.                 seat_matches.append(seat)
  33.             first_nums.popleft()
  34.             second_nums.pop()
  35.             break
  36.     else:
  37.         first_nums.append(first_nums.popleft())
  38.         second_nums.appendleft(second_nums.pop())
  39.  
  40.     if len(seat_matches) >= 3 or rotations >= 10:
  41.         break
  42.  
  43. print(f'Seat matches: {", ".join(seat_matches)}')
  44. print(f'Rotations count: {rotations}')
  45.  
  46.  
  47. ------------------------------------------------------------------------------------------
  48. # 02. CRUD
  49.  
  50.  
  51. def get_next_position(d, r, c):
  52.     if d == 'left':
  53.         return r, c - 1
  54.     elif d == 'right':
  55.         return r, c + 1
  56.     elif d == 'up':
  57.         return r - 1, c
  58.     elif d == 'down':
  59.         return r + 1, c
  60.  
  61.  
  62. SIZE = 6
  63. matrix = []
  64. for _ in range(SIZE):
  65.     matrix.append(input().split())
  66.  
  67. row, col = eval(input())
  68. while True:
  69.     command = input()
  70.     if command == 'Stop':
  71.         break
  72.     details = command.split(', ')
  73.     direction = details[1]
  74.     row, col = get_next_position(direction, row, col)
  75.  
  76.     if details[0] == 'Create':
  77.         create_value = details[2]
  78.         if matrix[row][col] == '.':
  79.             matrix[row][col] = create_value
  80.  
  81.     elif details[0] == 'Update':
  82.         update_value = details[2]
  83.         if matrix[row][col] != '.':
  84.             matrix[row][col] = update_value
  85.  
  86.     elif details[0] == 'Delete' and matrix[row][col] != '.':
  87.         matrix[row][col] = '.'
  88.  
  89.     elif details[0] == 'Read' and matrix[row][col] != '.':
  90.         print(matrix[row][col])
  91.  
  92. for el in matrix:
  93.     print(*el)
  94.  
  95.  
  96. ------------------------------------------------------------------------------------------
  97.  
  98. # 03. Song Creator
  99.  
  100.  
  101. def add_songs(*info):
  102.     final_print = ''
  103.     args_as_dict = {}
  104.     for el in info:
  105.         song_title = el[0]
  106.         lyrics = el[1]
  107.         if song_title not in args_as_dict:
  108.             args_as_dict[song_title] = []
  109.             args_as_dict[song_title].extend(lyrics)
  110.         else:
  111.             args_as_dict[song_title].extend(lyrics)
  112.  
  113.     for songs, lyrics in args_as_dict.items():
  114.         final_print += f'- {songs}\n'
  115.         for el in lyrics:
  116.             final_print += f'{el}\n'
  117.     return final_print
  118.  
  119.  
  120. ------------------------------------------------------------------------------------------
  121.  
  122.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement