Py||Palindrome

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/Lhw_666/article/details/102754597

题目描述
A string, if the same for both read and reverse read, is called a palindrome. Please write a program to determine if the input string is a palindrome.
输入
Enter the number of the string n, 0 < n ≤ 10000, after which n acts as a non-empty string, the string of each line consists of letters and numbers, and the length of the string does not exceed 1000.
输出
For each line of characters, if it is a palindrome, a line of “YES” is output, otherwise a line of “NO” is output.
样例输入 Copy
3
abba
abc
aa
样例输出 Copy
YES
NO
YES

import sys
def ss(s):
    if len(s)<2:
        return True
    if s[0]==s[-1]:
        return ss(s[1:-1])
    else:
        return False
n=int(input())
for i in range(n):
    s=[str(i) for i in input()]
    if ss(s)==True:
        print('YES')
    else:
        print('NO')

猜你喜欢

转载自blog.csdn.net/Lhw_666/article/details/102754597
py
今日推荐