本题要求编写程序,顺序输出给定字符串中所出现过的大写英文字母,每个字母只输出一遍;若无大写英文字母则输出“Not Found”。
输入格式:
输入为一个以回车结束的字符串(少于80个字符)。
输出格式:
按照输入的顺序在一行中输出所出现过的大写英文字母,每个字母只输出一遍。若无大写英文字母则输出“Not Found”。
输入样例1:
FONTNAME and FILENAME
输出样例1:
FONTAMEIL
输入样例2:
fontname and filrname
输出样例2:
Not Found
代码如下:
s = input()
temp = []
for i in range(len(s)):
if s[i] >= 'A' and s[i] <= 'Z':#找到第一个大写字母存入temp[]中
temp.append(s[i])
break
for i in range(len(s)):
if s[i] >= 'A' and s[i] <= 'Z' and s[i] not in temp[:len(temp)]:#找temp中没有的大写字母
temp.append(s[i])
if len(temp) == 0:
print("Not Found")
else:
print(''.join(temp))
提交结果: