Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Python Advanced Retake Exam - 19 August 2020
- #
- # https://judge.softuni.org/Contests/Practice/Index/2463#0
- #
- # 01. Taxi Express
- # 02. Minesweeper Generator
- # 03. Numbers Search
- ---------------------------------------------------------------------------------------------
- # 01. Taxi Express
- from collections import deque
- customers = deque([int(x) for x in input().split(', ')])
- taxis = deque([int(x) for x in input().split(', ')])
- total_time = sum(customers)
- while customers and taxis:
- first_customer = customers[0]
- last_taxi = taxis[-1]
- if last_taxi >= first_customer:
- customers.popleft()
- taxis.pop()
- if not customers:
- print(f'All customers were driven to their destinations')
- print(f'Total time: {total_time} minutes')
- else:
- print('Not all customers were driven to their destinations')
- if customers:
- print(f'Customers left: {", ".join(str(x) for x in customers)}')
- ---------------------------------------------------------------------------------------------
- # 02. Minesweeper Generator
- # New VERSION !
- def is_inside(r, c):
- return 0 <= r < SIZE and 0 <= c < SIZE
- def warning_calculate(bomb_indexes):
- for b in around_bomb:
- r, c = (bomb_indexes[0] + b[0], bomb_indexes[1] + b[1])
- if is_inside(r, c):
- if matrix[r][c] != '*':
- matrix[r][c] += 1
- around_bomb = [(0, 1), (0, -1), (-1, 0), (+1, 0), (1, 1), (-1, 1), (-1, -1), (1, -1)]
- SIZE = int(input())
- BOMBS = int(input())
- matrix = []
- for _ in range(SIZE):
- line = SIZE * '0'
- matrix.append([int(x) for x in list(line)])
- bombs_pos = []
- for _ in range(BOMBS):
- bomb_row_col = (input().strip('()').split(', '))
- row = int(bomb_row_col[0])
- col = int(bomb_row_col[1])
- matrix[row][col] = '*'
- bombs_pos.append((row, col))
- for bomb in bombs_pos:
- warning_calculate(bomb)
- for el in matrix:
- print(*el)
- ============================================================================================
- # 02. Minesweeper Generator
- # OLD VERSION !
- def is_inside_func(current_row, current_col):
- return 0 <= current_row < size and 0 <= current_col < size
- def calculate_bomb_warnings_func(row, col):
- warnings_count = 0
- if is_inside_func(row, col + 1): # RIGHT
- if matrix[row][col + 1] == '*':
- warnings_count += 1
- if is_inside_func(row, col - 1): # LEFT
- if matrix[row][col - 1] == '*':
- warnings_count += 1
- if is_inside_func(row + 1, col): # DOWN
- if matrix[row + 1][col] == '*':
- warnings_count += 1
- if is_inside_func(row - 1, col): # UP
- if matrix[row - 1][col] == '*':
- warnings_count += 1
- if is_inside_func(row - 1, col + 1): # TOP RIGHT
- if matrix[row - 1][col + 1] == '*':
- warnings_count += 1
- if is_inside_func(row - 1, col - 1): # TOP LEFT
- if matrix[row - 1][col - 1] == '*':
- warnings_count += 1
- if is_inside_func(row + 1, col - 1): # BOTTOM LEFT
- if matrix[row + 1][col - 1] == '*':
- warnings_count += 1
- if is_inside_func(row + 1, col + 1): # BOTTOM RIGHT
- if matrix[row + 1][col + 1] == '*':
- warnings_count += 1
- return warnings_count
- size = int(input())
- n_bombs = int(input())
- bombs_indexes = []
- matrix = []
- for _ in range(n_bombs): # Extracting bomb indexes
- current_bomb = eval(input())
- bomb_index1 = int(current_bomb[0])
- bomb_index2 = int(current_bomb[1])
- bombs_indexes.append((bomb_index1, bomb_index2))
- for row in range(size): # Creating the matrix
- matrix.append([])
- for cow in range(size):
- matrix[row].append(0)
- for current_index_bomb in bombs_indexes: # Placing the bombs
- index1 = current_index_bomb[0]
- index2 = current_index_bomb[1]
- if is_inside_func(index1, index2):
- matrix[index1][index2] = "*"
- for row_index in range(size):
- for col_index in range(size):
- if (row_index, col_index) not in bombs_indexes:
- warnings = calculate_bomb_warnings_func(row_index, col_index)
- matrix[row_index][col_index] = warnings
- for el in matrix:
- print(*el)
- ---------------------------------------------------------------------------------------------
- # 03. Numbers Search
- def numbers_searching(*nums):
- sorted_nums = sorted(nums)
- missing = []
- duplicated = []
- for num in range(sorted_nums[0], sorted_nums[-1] + 1):
- if num not in sorted_nums:
- missing.append(num)
- else:
- x = sorted_nums.count(num)
- if x > 1 and num not in duplicated:
- duplicated.append(num)
- missing.append(duplicated)
- return missing
- ---------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement