๋์ ์ฝ๋
for t in range(1,11):
length = int(input())
arr = []
cnt = 0
for _ in range(8):
arr.append(input())
for j in range(8):
b = [i[j] for i in arr]
for i in range(0,9-length):
if list(arr[j][i:length+i]) == list(reversed(arr[j][i:length+i])):
cnt += 1
if list(b[i:length+i]) == list(reversed(b[i:length+i])):
cnt += 1
print("#"+str(t) , cnt)
2์ฐจ์ ๋ฐฐ์ด์์ ํ ์ถ๋ ฅํ๊ธฐ
a = [
[0, 1],
[2, 3],
[4, 5],
[6, 7],
[8, 9],
]
b = [i[0] for i in a]
print(b)
# [0, 2, 4, 6, 8]
๋ฆฌ์คํธ ์์ ๋ค์ง๊ธฐ
list = [0,1,2,3,4]
list.reverse()
print(list)
# [4,3,2,1,0]
lst = [1,2,3,4,5]
print(list(reversed(lst)))
# [5,4,3,2,1]
reverse() : ๋ฉ์๋๋ ๋ฐํ ๊ฐ์ด ์์ง๋ง, ๋ฆฌ์คํธ์ ์๋ ๋ด์ฉ๋ฌผ์ ์์๋ฅผ ๋ค์ง์ต๋๋ค.
reversed() : ‘reversed’ ๊ฐ์ฒด๋ฅผ ๋ฐํํ๋ค. ๋ฐํ ๋ฐ์ผ๋ ค๋ฉด list ๋ก ๋ฐ๊พธ์ด ์ฌ์ฉํ์ .
if char == char[::-1]:
[::-1] ์ผ๋ก ๋ฌธ์ฅ์ ์ญ์์ ์ฝ๊ฒ ๊ตฌํ ์ ์๋ค.
'Algorithm > SWEA' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[SWEA - D3] 1225. ์ํธ์์ฑ๊ธฐ (0) | 2023.05.04 |
---|---|
[SWEA - D3] 1216. ํ๋ฌธ2 (0) | 2023.05.01 |
[SWEA - D3] 1217. ๊ฑฐ๋ญ ์ ๊ณฑ (0) | 2023.04.24 |
[SWEA - D3] 4406. ๋ชจ์์ด ๋ณด์ด์ง ์๋ ์ฌ๋ (0) | 2023.04.20 |
[SWEA - D3] 1206. View (0) | 2023.04.20 |