给定一个字符串,请写一段代码找出这个字符串中首先出现三次的那个英文字符(需要区分大小写)。
数据范围:字符串长度满足
n = input().replace(' ','') D = dict() length = len(n) for i in range(length): if n[i] not in D.keys() and 65<= ord(n[i]) <= 122: D[n[i]] = 1 elif 65<= ord(n[i]) <= 122: D[n[i]] += 1 if D[n[i]] == 3: print(n[i]) break else: continue
s = input().strip() dic = {} for ch in s: if ch.isalpha(): if ch not in dic: dic[ch] = 1 else: dic[ch] += 1 if dic[ch] == 3: print(ch) break
#! python3 #-*- ocidng:utf-8 -*- ''' 题目描述 给定一个英文字符串,请写一段代码找出这个字符串中首先出现三次的那个英文字符。 输入描述: 输入数据一个字符串,包括字母,数字等。 输出描述: 输出首先出现三次的那个英文字符 示例1 输入 Have you ever gone shopping and 输出 e ''' import sys if __name__=='__main__': 'doc' string=input() dict1={} for i in string: if i.isalpha(): dict1.setdefault(i,0) dict1[i]+=1 if dict1[i]>=3: print(i) break
def find(s): uper = [0] * 26 lower = [0] * 26 for char in s: if ord(char) >= ord('a') and ord(char) <= ord('z'): # is a lower letter index = ord(char) - ord('a') lower[index] += 1 if lower[index] ==3: return char if ord(char) >= ord('A') and ord(char) <= ord('Z'): # is a upper letter index = ord(char) - ord('A') uper[index] += 1 if uper[index] ==3: return char if __name__ == "__main__": s = input() char = find(s) print(char)