๋ฐ์ํ
๐ค๋ฌธ์ ํด๊ฒฐ
๐ป์์ค ์ฝ๋
T = int(input())
for test_case in range(1, T + 1):
N = int(input())
farm = [list(map(int, list(input().strip()))) for _ in range(N)]
m = N // 2 # ์ค์ฌ
answer = 0
for i in range(m+1): # ์์๋๊ฐ ๋์นญ์ด๋ฏ๋ก ์ ๋ฐ๊น์ง๋ง ๊ตฌํ๋ค.
for j in range(m - i, m + i + 1): # ์ค์ฌ์ ๊ธฐ์ค์ผ๋ก ์ผ์ชฝ์ผ๋ก 1์นธ, ์ค๋ฅธ์ชฝ์ผ๋ก 1์นธ ๋ฒ์๋ฅผ ๋๋ ค ๋๊ฐ๋ค.
answer += farm[i][j] + farm[N-i-1][j]
print(f'#{test_case} {answer - sum(farm[m])}') # ๊ฐ์ด๋ฐ๋ฅผ ๋๋ฒ ๋ํด์คฌ์ผ๋ฏ๋ก ํ๋ฒ์ ๋ค์ ๋นผ์ค๋ค.
๐๋ฌธ์ ํ์ธ
์ถ์ฒ: SW Expert Academy
๋ฐ์ํ
'Algorithm Problem > Python' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[python] SWEA - 4366. ์ ์์ด์ ์ํ์ ๋ฌด (0) | 2022.03.25 |
---|---|
[python] SWEA - 3347. ์ฌ๋ฆผํฝ ์ข ๋ชฉ ํฌํ (0) | 2022.03.24 |
[python] SWEA - 1225. [S/W ๋ฌธ์ ํด๊ฒฐ ๊ธฐ๋ณธ] 7์ผ์ฐจ - ์ํธ์์ฑ๊ธฐ (0) | 2022.03.22 |
[python] SWEA - 1209. [S/W ๋ฌธ์ ํด๊ฒฐ ๊ธฐ๋ณธ] 2์ผ์ฐจ - Sum (0) | 2022.03.21 |
[python] SWEA - 13547. ํ์จ๋ฆ (0) | 2022.02.22 |