Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Exercesis_Multidimensional_list
- # Diagonal_differences
- num = int(input())
- matrix = [[int(n) for n in input().split()] for row in range(num)]
- primary_sum = 0
- secondary_sum = 0
- for i in range(num):
- primary_sum += matrix[i][i]
- secondary_sum += matrix[i][num - i - 1]
- print(abs(primary_sum - secondary_sum))
- # Diagonals
- n = int(input())
- matrix = [[int(x) for x in input().split(", ")] for _ in range(n)]
- primary = [matrix[r][r] for r in range(n)] # взимаме числата от диагонала
- secondary = [matrix[r][n - r - 1] for r in range(n)] # взимаме числата от другия диагонала
- print(f"Primary diagonal: {', '.join(str(x) for x in primary)}. Sum: {sum(primary)}")
- print(f"Secondary diagonal: {', '.join(str(x) for x in secondary)}. Sum: {sum(secondary)}")
- # Matrix_of_palindromes
- rows, cols = [int(x) for x in input().split()]
- start = ord('a')
- for row in range(start, start + rows):
- for col in range(start, start + cols):
- print(f"{chr(row)}{chr(row + col - start)}{chr(row)}", end=" ")
- print() # За да извадим na нов ред
- # matrix_shiffling
- def check_valid_indices(indices):
- return {indices[0], indices[2]}.issubset(valid_rows) and {indices[1], indices[3]}.issubset(valid_cols)
- def swap_command(command: str, indices: list):
- if check_valid_indices(indices) and command == 'swap' and len(indices) == 4:
- row1, col1, row2, col2 = indices
- matrix[row1][col1], matrix[row2][col2] = matrix[row2][col2], matrix[row1][col1] # Разменяме местата
- print(*[' '.join(r) for r in matrix], sep="\n")
- else:
- print("Invalid input!")
- rows, cols = [int(x) for x in input().split()]
- matrix = [input().split() for _ in range(rows)]
- valid_rows = range(rows)
- valid_cols = range(cols)
- while True:
- command_type, *info = [int(x) if x.isdigit() else x for x in input().split()]
- if command_type == "END":
- break
- swap_command(command_type, inf
- # Maximal_sum
- rows, cols = [int(x) for x in input().split()]
- matrix = [[int(x) for x in input().split()] for row in range(rows)]
- max_sum = float("-inf")
- biggest_matrix = []
- for row in range(rows - 2):
- for col in range(cols - 2):
- first_row = matrix[row][col:col + 3]
- second_row = matrix[row + 1][col:col + 3]
- third_row = matrix[row + 2][col:col + 3]
- current_sum = sum(first_row) + sum(second_row) + sum(third_row)
- if current_sum > max_sum:
- max_sum = current_sum
- biggest_matrix = [first_row, second_row, third_row]
- print(f"Sum = {max_sum}")
- [print(*row) for row in biggest_matrix]
- # radioactive_mutant_vampire_bunnies
- def find_player_position():
- for row in range(rows):
- if "P" in matrix[row]:
- return row, matrix[row].index("P")
- def check_valid_index(row, col, player=False):
- global wins # За да можем да променяме wins във функцията
- if 0 <= row < rows and 0 <= col < cols:
- return True
- if player:
- wins = True
- def bunnies_positions():
- positions = []
- for row in range(rows):
- for col in range(cols):
- if matrix[row][col] == "B":
- positions.append([row, col])
- return positions
- def bunnies_move(bunnies_pos):
- for row, col in (bunnies_pos):
- for bunnie_move in direction.values():
- new_row, new_col = row + bunnie_move[0], col + bunnie_move[1]
- if check_valid_index(new_row, new_col):
- matrix[new_row][new_col] = "B"
- def show_resilts(status="won"):
- [print(*row, sep="") for row in matrix]
- print(f"{status}: {player_row} {player_col}")
- raise SystemExit
- def check_player_alive(row, col):
- if matrix[row][col] == "B":
- show_resilts("dead")
- rows, cols = [int(x) for x in input().split()]
- matrix = [list(input()) for _ in range(rows)]
- commands = input()
- wins = False
- direction = {
- "U": (-1, 0), # Посоката в която се движим
- "D": (1, 0),
- "L": (0, -1),
- "R": (0, 1)
- }
- player_row, player_col = find_player_position()
- matrix[player_row][player_col] = '.'
- for command in commands:
- player_movement_row, player_movement_col = player_row + direction[command][0], player_col + direction[command][1]
- if check_valid_index(player_movement_row, player_movement_col, True):
- player_row, player_col = player_movement_row, player_movement_col
- bunnies_move(bunnies_positions())
- if wins:
- show_resilts()
- check_player_alive(player_row, player_col)
- # Snake_moves
- from collections import deque
- rows, cols = [int(x) for x in input().split()]
- word = list(input()) # abc -> ["a", "b", "c"]
- word_copy = deque(word)
- for row in range(rows):
- while len(word_copy) < cols:
- word_copy.extend(word)
- if row % 2 == 0:
- print(*[word_copy.popleft() for _ in range(cols)], sep="")
- else:
- print(*[word_copy.popleft() for _ in range(cols)][::-1], sep="")
- # Two_by_two_squares_in_matrix
- rows, cols = [int(x) for x in input().split()]
- matrix = [input().split() for row in range(rows)]
- equal_blocks = 0
- for row in range(rows - 1):
- for col in range(cols - 1):
- symbol = matrix[row][col]
- if matrix[row][col + 1] == symbol and matrix[row + 1][col] == matrix[row + 1][col + 1] == symbol:
- equal_blocks += 1
- print(equal_blocks)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement