-
17276 배열 돌리기코테 대비 python/백준 2022. 8. 22. 11:32
https://www.acmicpc.net/problem/17276
# import time # start = time.time() test = int(input()) def turning( n, d, a: list, main_line: list, vertical: list, sub_line: list, horizon: list ): if d > 0: k = int(d / 45) for i in range(k): tmp = [] tmp2 = [] # 주대각선 # print("right") tmp = vertical vertical = main_line tmp2 = sub_line sub_line = tmp tmp = horizon horizon = tmp2 main_line = tmp[::-1] # print(main_line) else: k = int(abs(d) / 45) for i in range(k): #print("left") tmp = [] tmp2 = [] tmp = vertical vertical = sub_line tmp2 = main_line main_line = tmp tmp = horizon horizon = tmp2[::-1] sub_line = tmp # print(horizon) for i in range(n): a[i][int((n + 1) / 2) - 1] = vertical[i] a[i][i] = main_line[i] a[int((n + 1) / 2) - 1][n - i - 1] = horizon[i] a[i][n - i - 1] = sub_line[i] # print(a) return a for t in range(test): n, d = map(int, input().split()) a = [] for _ in range(n): a.append(list(map(int, input().split()))) main_line = [] horizon = [] sub_line = [] vertical = [] # 주대각선 for _ in range(n): main_line.append(a[_][_]) # 세로 for _ in range(n): vertical.append(a[_][int((n + 1) / 2) - 1]) # 부대각선 for _ in range(n): sub_line.append(a[_][n - _ - 1]) # 가로 for _ in range(n): horizon.append(a[int((n + 1) / 2) - 1][n - _ - 1]) turning(n, d, a, main_line, vertical, sub_line, horizon) for i in range(n): for j in range(n): print(a[i][j], end=" ") # print() # print("time :", time.time() - start)
저번주에 못풀었던 문제를 마음글 가다듬고 오늘 풀었다.. ㅎㅎ
휴~~
'코테 대비 python > 백준' 카테고리의 다른 글
11723 집합 (0) 2022.08.30 16173 점프왕 쩰리 (0) 2022.08.23 1475 방 번호 (0) 2022.08.22 1475 방 번호 (0) 2022.08.19 11866 요세푸스 (0) 2022.08.19