问题描述
问题:
给定字符串S,找到最大的字母字符,其大写和小写字母均出现在S中。应返回大写字符。例如,对于S =“ admeDCAB”,返回“ D”。如果没有这样的字符,请返回“ NO”。
s=input()
l=[0]*26
u=[0]*26
ln=len(s)
for i in range(ln):
if(s[i].islower()):
l[int(ord(s[i])-ord(('a')))]=1
else:
u[int(ord(s[i])-ord(('A')))]=1
for i in range(25,-1,-1):
if(l[i]==1 and u[i]==1):
print(chr(i+ord('A')))
print(NO)
一旦打印出(chr(i + ord('A'))))如何退出
解决方法
要回答您的实际问题,
给定字符串S,找到最大的字母字符,其大写和小写字母均出现在S中。应返回大写字符。例如,对于S =“ admeDCAB”,返回“ D”。如果没有这样的字符,请返回“ NO”。
以Python方式,
def f(s):
s = set(s)
for c in 'ZYXWVUTSRQPONMLKJIHGFEDCBA':
if c in s and c.lower() in s:
return c
return 'NO'