SSAFY/SWEA

[SWEA] #1216. 회문 2_파이썬

728x90
반응형

풀기 전 생각해보기😮


풀이🛫

# 회문 2
T = 10
for t in range(T):
    tc = int(input())
    arr = [list(input()) for i in range(100)]
    
    totalLi = []
    for col in range(100):
        for row in range(100):
            # 짝수 개가 같을 때
            if arr[col][row-1] == arr[col][row]:
                l = 1
                while 0<=row-1-l<100 and 0<=row+l<100 and arr[col][row-1-l] == arr[col][row+l]:
                    l += 1
                if l != 1:
                    totalLi.append(2*l)
            # 홀수 개가 같을 때
            if 0<=row+1<100 and arr[col][row-1] == arr[col][row+1]:
                l = 1
                while 0<=row-1-l<100 and 0<=row+1+l<100 and arr[col][row-1-l] == arr[col][row+1+l]:
                    l += 1
                if l != 1:
                    totalLi.append(2*l+1)

    for row in range(100):
        tempLi = []
        for col in range(100):
            # 짝수 개가 같을 때
            if 0<=col-1<100 and arr[col-1][row] == arr[col][row]:
                l = 1
                while 0<=col-1-l<100 and 0<=col+l<100 and arr[col-1-l][row] == arr[col+l][row]:
                    l += 1
                if l != 1:
                    totalLi.append(2*l)

            #홀수 개가 같을 때
            if 0<=col-1<100 and 0<=col+1<100 and arr[col-1][row] == arr[col+1][row]:
                l = 1
                while 0<=col-1-l<100 and 0<=col+1+l<100 and arr[col-1-l][row] == arr[col+1+l][row]:
                    l += 1
                if l != 1:
                    totalLi.append(2*l+1)

    answer = 0    
    for i in totalLi:
        if answer < i:
            answer = i

    print(f"#{tc}", answer)

 

핵심 정리🎁

  • 이전에 풀었던 회문 문제와 같다. 이전 문제를 풀 수 있다면 쉽게 작성할 수 있을 것

 

링크💎

 

SW Expert Academy

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

swexpertacademy.com

 

후기 😎

  • 클린코드는 아니지만, 내가 하고자 하는 바를 담아서 꾸역꾸역 정답을 맞춰봤단 점에서 스스로에게 칭찬을.. 

 

 

 

'SSAFY > SWEA' 카테고리의 다른 글

[SWEA] #10989. 폭격 작전_파이썬  (0) 2022.08.23
[SWEA] #4866. 괄호 검사_파이썬  (0) 2022.08.17
[SWEA] #4861. 회문_파이썬  (0) 2022.08.16
[SWEA] #12712. 파리퇴치3_파이썬  (0) 2022.08.16
[SWEA] 1959. 두 개의 숫자열  (0) 2022.08.15