cool hamsters never sleep
백준 10988. 팰린드롬인지 확인하기 본문
w = list(input())
s = list(reversed(w))
if w == s :
print(1)
else :
print(0)
처음에 sorted(리스트 명, reverse = True)를 사용하려 했으나
이 경우에 아예 정렬을 하므로 단순 뒤집기가 아니게 되버림
따라서 reversed()로 단순 뒤집기만 함
아래는 abba 를 입력했을 때의 반례가 존재하는 잘못된 코드
w = list(input())
s = sorted(w, reverse = True)
x = 0
for i in range (len(w)) :
if w[i] == s[i] :
x = x + 1
if x == len(w) :
print(1)
else :
print(0)
'Python Algorithm' 카테고리의 다른 글
백준 2435. 기상청 인턴 신현수 (0) | 2022.09.15 |
---|---|
백준 2754. 학점계산 (0) | 2022.09.14 |
백준 10886. 0 = not cute / 1 = cute (0) | 2022.09.13 |
백준 10102. 개표 (0) | 2022.09.08 |
백준 2775. 부녀회장이 될테야 (0) | 2022.09.07 |
Comments