정리
백준 17609번: 회문 본문
백준 17609번: 회문

<Python Code>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 유사회문 판단 함수 | |
def pseudo(a, left, right): | |
while left < right: | |
if a[left] == a[right]: | |
left += 1 | |
right -= 1 | |
else: | |
return False | |
return True | |
# 회문 판단 함수 | |
def palindrome(a, left, right): | |
while left < right: | |
if a[left] == a[right]: | |
left += 1 | |
right -= 1 | |
else: | |
res1 = pseudo(a, left+1, right) | |
res2 = pseudo(a, left, right-1) | |
if res1 == True or res2 == True: | |
return 1 | |
else: | |
return 2 | |
return 0 | |
T = int(input()) | |
for i in range(T): | |
a = list(input()) | |
res = palindrome(a, 0, len(a)-1) | |
print(res) |
'Programming > 백준 BOJ' 카테고리의 다른 글
백준 2839번: 설탕 배달 (0) | 2020.08.30 |
---|---|
백준 1931번: 회의실배정 (0) | 2020.08.24 |
백준 2212번: 센서 (0) | 2020.07.29 |
백준 1092번: 배 (0) | 2020.07.27 |
백준 2512번: 예산 (0) | 2020.07.23 |
Comments