🧩 문제

🧩 문제 해석
- 특정한 행을 회전 명령마다 주어진 칸 만큼 회전한 후
- 회전을 마친 배열을 행마다 슬라이싱하여 값을 출력한다.
🏁 내 풀이
from collections import deque
n = 5
mat = [list(map(int, input().split())) for _ in range(n)]
m = int(input())
for i in range(m):
row, direction, num = map(int, input().split())
now = deque(mat[row-1])
if direction == 0:
now.rotate(-num)
else:
now.rotate(num)
mat[row-1]=list(now)
persi = 0
s = 0
for i in range(n):
if i <= n//2:
persi += sum(mat[i][s:n-s])
s += 1
else:
s -= 1
persi += sum(mat[i][s-1:n-s+1])
print(persi)
- collections 라이브러리의 deque를 사용하여 회전했다.
(pop pop 구현도 좋지만 라이브러리를 잘 사용하는 것도 좋다고 생각함)
- 사과나무(다이아몬드)에서의 풀이를 사용하여 슬라이싱 위치를 넣을 변수를 생성하여 조금 더 간단하고 보기 쉽게 짜보았다.