Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Python Advanced Retake Exam - 18 August 2022
- # https://judge.softuni.org/Contests/Practice/Index/3534#2
- # 01. Stewards
- # 02. CRUD
- # 03. Song Creator
- ------------------------------------------------------------------------------------------
- # 01. Stewards
- from collections import deque
- all_seats = input().split(', ')
- first_nums = deque([int(x) for x in input().split(', ')])
- second_nums = deque([int(x) for x in input().split(', ')])
- rotations = 0
- seat_matches = []
- while True:
- first_first = first_nums[0]
- last_second = second_nums[-1]
- rotations += 1
- sum_result = first_first + last_second
- searched_letter = chr(sum_result)
- for seat in all_seats:
- if str(first_first) + searched_letter == seat or str(last_second) + searched_letter == seat:
- if seat not in seat_matches:
- seat_matches.append(seat)
- first_nums.popleft()
- second_nums.pop()
- break
- else:
- first_nums.append(first_nums.popleft())
- second_nums.appendleft(second_nums.pop())
- if len(seat_matches) >= 3 or rotations >= 10:
- break
- print(f'Seat matches: {", ".join(seat_matches)}')
- print(f'Rotations count: {rotations}')
- ------------------------------------------------------------------------------------------
- # 02. CRUD
- def get_next_position(d, r, c):
- if d == 'left':
- return r, c - 1
- elif d == 'right':
- return r, c + 1
- elif d == 'up':
- return r - 1, c
- elif d == 'down':
- return r + 1, c
- SIZE = 6
- matrix = []
- for _ in range(SIZE):
- matrix.append(input().split())
- row, col = eval(input())
- while True:
- command = input()
- if command == 'Stop':
- break
- details = command.split(', ')
- direction = details[1]
- row, col = get_next_position(direction, row, col)
- if details[0] == 'Create':
- create_value = details[2]
- if matrix[row][col] == '.':
- matrix[row][col] = create_value
- elif details[0] == 'Update':
- update_value = details[2]
- if matrix[row][col] != '.':
- matrix[row][col] = update_value
- elif details[0] == 'Delete' and matrix[row][col] != '.':
- matrix[row][col] = '.'
- elif details[0] == 'Read' and matrix[row][col] != '.':
- print(matrix[row][col])
- for el in matrix:
- print(*el)
- ------------------------------------------------------------------------------------------
- # 03. Song Creator
- def add_songs(*info):
- final_print = ''
- args_as_dict = {}
- for el in info:
- song_title = el[0]
- lyrics = el[1]
- if song_title not in args_as_dict:
- args_as_dict[song_title] = []
- args_as_dict[song_title].extend(lyrics)
- else:
- args_as_dict[song_title].extend(lyrics)
- for songs, lyrics in args_as_dict.items():
- final_print += f'- {songs}\n'
- for el in lyrics:
- final_print += f'{el}\n'
- return final_print
- ------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement