找出字符串中第一个只出现一次的字符
数据范围:输入的字符串长度满足
a = input() dic = {} for i in a: if i not in dic: dic[i] = a.count(i) if dic[i] == 1: break if dic[i] == 1: print(i) else: print(-1)
s=input() def frist(s): for i in s: if s.count(i)==1: return i if frist(s): print(frist(s)) else: print(-1)
a=input() for one in a: if a.count(one)==1: print(one) break else: print(-1)
def first_str(n): for i in n: if n.count(i)==1: return i return -1 print(first_str(input()))
while True: try: str_in = input() # 记录只出现一次的字符有哪些 str2num = {} lst = [] for s in str_in: if s not in list(str2num.keys()): str2num[s] = 0 str2num[s]+=1 if s not in lst: lst.append(s) if not min(list(str2num.values()))==1: print(-1) else: for s in lst: if str2num[s] == 1: print(s) break break # 打印第一个只出现一次的字符,否则打印-1 except: break
while True: try: a = input() b = {} d = set() for i in range(len(a)): if a[i] not in d: if a[i] not in b: b[a[i]] = [i] else: del b[a[i]] d.add(a[i]) e = [] for j in b.values(): e.extend(j) if e: e.sort() print(a[e[0]]) else: print('-1') except: break
from collections import Counter while True: try: words = input() length = len(words) words_dict = Counter(words) if 1 in words_dict.values(): temp_list = [] for i in words_dict.keys(): if words_dict[i] == 1: temp_list.append(i) # temp_dict = {} # for i in range(length): # if words[i] in temp_list: # temp_dict[i] = words[i] # print(temp_dict[min(temp_dict.keys())]) for i in range(length): if words[i] in temp_list: print(words[i]) break else: print(-1) except: break
s=str(input()) l=[] for i in s: x=s.count(i) if x==1: l.append(i) if len(l)!=0: print(l[0]) else: print(-1)