백준(1259) - 팰린드롬수 Python

최대 1 분 소요

백준(1259) - 팰린드롬수

문제풀이: 그리디, 파이썬

해결방법
  • 입력받은 data를 data[i] , data[-i] 와 같은지 확인하면 된다.

  • 리스트의 첫번째 인자는 0이므로, 맨 앞에 아무 숫자나 추가해 준 후

    data[i] , data[-i] 가 같은지 비교하면 된다.

import sys
input = sys.stdin.readline

while 1:
    data = int(input())
    if data == 0:
        break
    str_data = '1' + str(data)
    chk = True
    size = (len(str_data) - 1)//2
    for i in range(1, size+1):
        if chk == False:
            break
        if str_data[i] != str_data[-i]:
            chk = False
    if chk:
        print("yes")
    else:
        print("no")

댓글남기기