Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Python Advanced Retake Exam - 16 December 2020
- #
- # https://judge.softuni.org/Contests/Practice/Index/2720#0
- #
- # 01. Matching
- # 02. Game of Words
- # 03. Magic Triangle
- -----------------------------------------------------------------------------------------
- # 01. Matching
- from collections import deque
- males = deque([int(x) for x in input().split() if int(x) > 0])
- females = deque([int(x) for x in input().split() if int(x) > 0])
- matches = 0
- while True:
- if not females or not males:
- break
- last_male = males[-1]
- first_female = females[0]
- if last_male % 25 == 0:
- males.pop()
- if males:
- males.pop()
- continue
- if first_female % 25 == 0:
- females.popleft()
- if females:
- females.popleft()
- continue
- if last_male == first_female:
- matches += 1
- males.pop()
- females.popleft()
- else:
- females.popleft()
- males[-1] -= 2
- if males[-1] <= 0:
- males.pop()
- print(f"Matches: {matches}")
- if not males:
- print("Males left: none")
- else:
- males = reversed(males)
- print(f'Males left: {", ".join(str(x) for x in males)}')
- if not females:
- print("Females left: none")
- else:
- print(f'Females left: {", ".join(str(x) for x in females)}')
- -----------------------------------------------------------------------------------------
- # 02. Game of Words
- def is_inside(r, c):
- return 0 <= r < SIZE and 0 <= c < SIZE
- 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
- word = input()
- SIZE = int(input())
- matrix = []
- row, col = 0, 0
- for row_index in range(SIZE):
- matrix.append(list(input()))
- for col_index in range(SIZE):
- if matrix[row_index][col_index] == 'P':
- row, col = row_index, col_index
- matrix[row][col] = '-'
- total_steps = int(input())
- for _ in range(total_steps):
- step = input()
- next_row, next_col = get_next_position(step, row, col)
- if not is_inside(next_row, next_col):
- word = word[:-1]
- else:
- row, col = next_row, next_col
- if matrix[row][col] not in ['P', '-']:
- word += matrix[row][col]
- matrix[row][col] = '-'
- matrix[row][col] = 'P'
- print(word)
- for el in matrix:
- print(*el, sep='')
- -----------------------------------------------------------------------------------------
- # 03. Magic Triangle
- def get_magic_triangle(n):
- matrix = [[1], [1, 1]]
- counter1 = 0
- counter2 = 0
- for row in range(2, n):
- matrix.append([])
- counter1 += 1
- for col in range(counter1):
- if len(matrix) <= 3:
- matrix[row].append(sum(matrix[counter1]))
- else:
- counter2 += 1
- matrix[row].append(sum(matrix[counter1][col:counter2 + 1]))
- counter2 = 0
- matrix[row].append(1)
- matrix[row].insert(0, 1)
- return matrix
- -----------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement