Problem :

https://www.hackerrank.com/challenges/matrix-rotation-algo/problem


My Solution :

#!/usr/bin/env python3


def matrixRotation(matrix):
    for i in range(min(m, n)//2):
        count = 2*(m+n-2) - 8*(i)
        rotate = r % count
        while 0 < rotate:
            temp = matrix[i][i]
            matrix[i][i:n-1-i] = matrix[i][i+1:n-i]
            for j in range(i+1, m-i):
                matrix[j-1][n-1-i] = matrix[j][n-1-i]
            matrix[m-1-i][i+1:n-i] = matrix[m-1-i][i:n-1-i]
            for j in range(m-2-i, i-1, -1):
                matrix[j+1][i] = matrix[j][i]
            matrix[i+1][i] = temp
            rotate -= 1


m, n, r = map(int, input().split())
matrix = []
for _ in range(m):
    matrix.append(list(map(int, input().rstrip().split())))
matrixRotation(matrix)

for line in matrix:
    print(' '.join(map(str, line)))
  1. BlogIcon 먹튀
    2018.09.02 03:25 신고

    감사합니다 ~

  2. BlogIcon 쉔필드
    2018.09.02 03:54 신고

    오호..요즘도 꾸준히 작업하고 계시는군요. 오랜만에 생각나서 들러봅니다