-
Notifications
You must be signed in to change notification settings - Fork 0
/
[swea] 1215. [SW 문제해결 기본] 3일차 - 회문1.py
64 lines (55 loc) · 1.68 KB
/
[swea] 1215. [SW 문제해결 기본] 3일차 - 회문1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
T = 10
for test_case in range(1, T+1):
letter = int(input())
pan = [list(map(int, input())) for _ in range(8)]
cnt = 0
#가로(행이동)
for r in range(8):
#회문 생성 횟수
for c in range(8-letter+1):
#회문 길이만큼 슬라이싱
if pan[r][c:c+letter] == pan[r][c:c+letter][::-1]:
cnt += 1
#세로(열이동)
for c in range(8):
for r in range(8-letter+1):
char = ''
#r번째 행부터 회문의 길이에 해당하는 회문을 char에 넣기
for r2 in range(r, r+letter):
char += pan[r2][c]
if char == char[::-1]:
cnt += 1
print("#{} {}".format(test_case, cnt))
----------------------------------
23.05.08
import math
for test_case in range(1, 11):
answer = 0
hoi = int(input())
pan = []
for i in range(8):
pan.append(list(input().rstrip()))
pan2 = list(zip(*pan))
for i in range(8):
for j in range(9-hoi):
p_list = pan[i][j:hoi + j]
p_list2 = pan2[i][j:hoi + j]
start = 0
end = hoi - 1
for _ in range(int(math.ceil(hoi/2))):
if p_list[start] != p_list[end]:
break
start += 1
end -= 1
else:
answer += 1
start2 = 0
end2 = hoi - 1
for _ in range(int(math.ceil(hoi/2))):
if p_list2[start2] != p_list2[end2]:
break
start2 += 1
end2 -= 1
else:
answer += 1
print("#{} {}".format(test_case, answer))