# 第一题 判断字符串是否是回文
str = input("输入字符串:")
num = len(str)
str = list(str)
print(str)
restr = list(reversed(str))
print(restr)
if str == restr:
print(True)
else:
print(False)
# 第二题 找出最大的回文子串
str = input()
str = list(str)
restr = list(reversed(str))
count = None
sum1 = 0
sum2 = 0
if len(str) == 0:
print(0)
elif len(str) == 1:
print(0)
else:
for i in range(0, len(str)):
count = 0
for j in range(0, len(restr)):
if str[i] == restr[j]:
count += 1
if count > sum1:
sum1 = count
if i < (len(str)) - 1:
i += 1
else:
break
else:
break
for i in range(0, len(restr)):
count = 0
for j in range(0, len(str)):
if restr[i] == str[j]:
count += 1
if count > sum2:
sum2 = count
if i < (len(restr)) - 1:
i += 1
else:
break
else:
break
print(max(sum1, sum2), end='')
# 第三题 偶数序号大写,奇数序号小写
str = input()
str1= ''
for i in range (0,len(str)):
if i% 2 ==0:
str1 += str[i].upper()
else:
str1 += str[i].lower()
print(str1)
05字符串
最新推荐文章于 2024-08-19 14:41:29 发布