题目
描述
找出字符串中第一个只出现一次的字符
输入描述:
输入几个非空字符串
输出描述:
输出第一个只出现一次的字符,如果不存在输出-1
示例1
输入:
asdfasdfo
aabb
输出:
o
-1
解题思路
(1)用count函数对输入的字符串的每个的数量进行计算,存入data
(2)判断data中是否存在数量为1的字符,没有输出-1,有则输出第一个出现1的位置对应的字符
代码
while True:
try:
in_str = input()
data = []
for char in in_str:
data.append(in_str.count(char))
if 1 in data:
print(in_str[data.index(1)])
else:
print(-1)
except:
break