본문 바로가기
코딩테스트/SW Expert Academy

1215. [S/W 문제해결 기본] 3일차 - 회문1

by brown_board 2022. 11. 18.
728x90

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=3&contestProbId=AV14QpAaAAwCFAYi&categoryId=AV14QpAaAAwCFAYi&categoryType=CODE&problemTitle=&orderBy=RECOMMEND_COUNT&selectCodeLang=ALL&select-1=3&pageSize=10&pageIndex=1 

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

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
for test in range(1,11):
    #회문길이
    n = int(input())
    #퍼즐 입력받기
    array= []
    for i in range(8):
        array.append(input())
 
    temp = []
    count =0
 
    # 가로 조사
    for row in range(8):
        for start in range(8-n+1):
            for col in range(start, start+n):
                temp.append((array[row][col]))
            #회문이라면
            if temp == temp[::-1]:
                count += 1
            temp = []
 
    # 세로 조사
    for row in range(8):
        for start in range(8-n+1):
            for col in range(start, start+n):
                temp.append((array[col][row]))
            #회문이라면
            if temp == temp[::-1]:
                count += 1
            temp = []
 
    print(f'#{test} {count}')
cs
728x90

댓글