Answer to Question #220298 in Python for Latha

Question #220298

Question #168149

For each Query operation print the element present at row index K and column index L of the matrix in its current state.

For Input:

2

5 6

7 8

R 90

Q 0 1

R 270

Q 1 1

R 180

U 0 0 4

Q 0 0

-1


Here , you are providing the expert code. But, the code passed only 3/7 test cases. Whenever i tried with above input i will get 5 8 5.But, actual output is 5 8 8.


1
Expert's answer
2021-07-25T08:38:03-0400
def ReadMatrix():
    matrix = []
    for i in range(int(input())):
        row = [int(j) for j in input().split()]
        matrix.append(row) 
    return matrix

def RotateMatrix(matrix, degrees):
    n = len(matrix[0])
    rotations = (degrees // 90) % 4
    for r in range(rotations):
        temp_matrix = []
        for i in range(n):
            column = [row[i] for row in matrix]
            column.reverse()
            temp_matrix.append(column)
        matrix = temp_matrix
    return matrix

matrix = ReadMatrix()
rotation = 0

while True:
    line = input().split()
    if line[0] == "-1":
        break;
    elif line[0] == "R":
        rotation += int(line[1])
        matrix = RotateMatrix(matrix, int(line[1]))
    elif line[0] == "U":
         matrix[int(line[1])][int(line[2])] = int(line[3])
         matrix = RotateMatrix(matrix, rotation)
    elif line[0] == "Q":
        print(matrix[int(line[1])][int(line[2])])
    else:
        print("Error: unexpected command '" + line[0] + "'")
        exit(1)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS