백준 5670 - 휴대폰 자판


백준 5670 - 휴대폰 자판

123456789101112131415161718192021222324252627282930313233import sysfrom collections import defaultdict try: while True: n = int(sys.stdin.readline()) dic = defaultdict(list) words = [] for i in range(n): word = sys.stdin.readline().rstrip() words.append(word) tmp = "" for w in word: if tmp != "" and w not in dic[tmp]: dic[tmp].append(w) tmp += w ans = [] for word in words: cnt = 1 tmp = "" for w in word: if len(word) == 1: break tmp += w if len(dic[tmp]) > 1 or tmp != word and tmp in words: cnt += 1 ans.append(cnt) print("{:.2f}".format(sum(ans)/n)) except: exit()Colored by Color Scriptercs..........



원문링크 : 백준 5670 - 휴대폰 자판