T-coding
백준 1022 소용돌이 예쁘게 출력하기 / Python 본문
728x90
728x90
https://www.acmicpc.net/problem/1022
1022번: 소용돌이 예쁘게 출력하기
첫째 줄에 네 정수 r1, c1, r2, c2가 주어진다.
www.acmicpc.net

코드
더보기
r1, c1, r2, c2 = map(int, input().split())
arr = [[0] * (c2 - c1 + 1) for _ in range(r2 - r1 + 1)]
max_num = 0
def cal(r, c):
bor = max(abs(r), abs(c))
default = (bor * 2 - 1) ** 2 + 1
if r == bor:
return default + bor * 7 + c - 1
if c == -bor:
return default + bor * 5 + r - 1
if r == -bor:
return default + bor * 3 - c - 1
return default + bor - r - 1
for i in range(r1, r2 + 1):
for j in range(c1, c2 + 1):
arr[i - r1][j - c1] = cal(i, j)
max_num = max(max_num, arr[i - r1][j - c1])
for i in range(r2 - r1 + 1):
for j in range(c2 - c1 + 1):
print(str(arr[i][j]).rjust(len(str(max_num))), end=" ")
print()
728x90
300x250
'Baekjoon' 카테고리의 다른 글
백준 1074 Z / Python (0) | 2023.03.18 |
---|---|
백준 1029 그림 교환 / Python (0) | 2023.03.18 |
백준 7569 토마토 / Python (0) | 2023.03.17 |
백준 25206 너의 평점은 / Python (0) | 2023.03.16 |
백준 5347 LCM / Python (0) | 2023.03.16 |