Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def not_valid_coordinates(anyrow1, anycol1, anyrow2, anycol2, anyrows, anycols):
- return anyrow1 < 0 or anyrow2 < 0 or anycol1 < 0 or anycol2 < 0 \
- or anyrows <= anyrow1 or anyrows <= anyrow2 or anycols <= anycol1 or anycols <= anycol2
- rows, cols = [int(n) for n in input().split()]
- matrix = []
- for r in range(rows):
- current_row = input().split()
- matrix.append(current_row)
- while True:
- command_line = input().split()
- if "END" in command_line:
- break
- elif len(command_line) != 5 or command_line[0] != "swap":
- print("Invalid input!")
- continue
- row1, col1, row2, col2 = [int(n) for n in command_line[1:]]
- if not_valid_coordinates(row1, col1, row2, col2, rows, cols):
- print("Invalid input!")
- continue
- matrix[row1][col1], matrix[row2][col2] = matrix[row2][col2], matrix[row1][col1]
- for row in range(rows):
- print(*matrix[row])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement