Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 06. Matrix Shuffling
- # https://judge.softuni.org/Contests/Practice/Index/1835#5
- # Multidimensional Lists - Exercise 1
- def is_outside(row, col, rows, cols):
- return row < 0 or col < 0 or row >= rows or col >= cols
- size = input().split()
- rows = int(size[0])
- cols = int(size[1])
- matrix = []
- for _ in range(rows):
- matrix.append(input().split(' '))
- command = input()
- while not command == 'END':
- command = command.split()
- if command[0] != 'swap' or len(command) != 5:
- print('Invalid input!')
- command = input()
- continue
- row1 = int(command[1])
- col1 = int(command[2])
- row2 = int(command[3])
- col2 = int(command[4])
- if is_outside(row1, col1, rows, cols) or is_outside(row2, col2, rows, cols):
- print('Invalid input!')
- command = input()
- continue
- matrix[row1][col1], matrix[row2][col2] = matrix[row2][col2], matrix[row1][col1]
- for el in matrix:
- print(*el)
- command = input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement