[HackerRank][Python3] Matrix Layer Rotation
2018. 8. 8. 01:43 |
프로그래밍/HackerRank
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)))
'프로그래밍 > HackerRank' 카테고리의 다른 글
[HackerRank][Python3] Waiter (0) | 2018.09.03 |
---|---|
[HackerRank][Python3] Simple Text Editor (0) | 2018.09.02 |
[HackerRank][Python3] Equal Stacks (0) | 2018.09.02 |
[HackerRank][Python3] Maximum Element (0) | 2018.09.02 |
[HackerRank][Python3] Dijkstra: Shortest Reach 2 (0) | 2018.08.07 |
[HackerRank][Python3] Tries: Contacts (0) | 2018.08.05 |
[HackerRank][Python3] Swap Nodes [Algo] (0) | 2018.07.27 |
[HackerRank][Python3] Special Palindrome Again (0) | 2018.07.23 |
최근에 달린 댓글 최근에 달린 댓글