方便记忆的电话号码

方便记忆的电话号码

描述

英文字母(除Q和Z外)和电话号码存在着对应关系,如下所示:

A,B,C -> 2

D,E,F -> 3

G,H,I -> 4

J,K,L -> 5

M,N,O -> 6

P,R,S -> 7

T,U,V -> 8

W,X,Y -> 9

标准的电话号码格式是xxx-xxxx,其中x表示0-9中的一个数字。有时为了方便记忆电话号码,我们会将电话号码的数字转变为英文字母,如把263-7422记成America。有时,我们还加上“-”作为分隔符,如把449-6753记成Hi-World。当然,我们未必要将所有的数字都转变为字母,比如474-6635可以记成iPhone-5。

总之,一个方便记忆的电话号码由数字和除Q、Z外的英文字母组成,并且可以在任意位置插入任意多的“-”符号。

现在 ,我们有一个列表,记录着许多方便记忆的电话号码。不同的方便记忆的电话号码可能对应相同的标准号码,你的任务就是找出它们。

 

输入

第一行是一个正整数n(n <= 100000),表示列表中的电话号码数。
其后n行,每行是一个方便记忆的电话号码,它由数字和除Q、Z外的英文字母、“-”符号组成,其中数字和字母的总数一定为7,字符串总长度不超过200。

输出

输出包括若干行,每行包括一个标准电话号码(xxx-xxxx)以及它重复出现的次数k(k >= 2),中间用空格分隔。输出的标准电话号码需按照升序排序。

如果没有重复出现的标准电话号码,则输出一行“No duplicates.”。

样例输入

12
4873279
ITS-EASY
888-4567
3-10-10-10
888-GLOP
TUT-GLOP
967-11-11
310-GINO
F101010
888-1200
-4-8-7-3-2-7-9-
487-3279

样例输出

310-1010 2
487-3279 4
888-4567 3 

 

参考代码

n=int(input())
list_convenient=[]
for i in range(n):
    list_convenient.append(str(input()))


def ConvenirntToStandard(con_str):
    sta_str=""
    con_str=con_str.upper()
    con_str=con_str.replace("-","")
    
    for cha in con_str:
        
        if(cha=='0'):
            sta_str=sta_str+"0"
            continue
        if(cha=='1'):
            sta_str=sta_str+"1"
            continue
        if(cha=='A' or cha=='B' or cha=='C' or cha=='2'):
            sta_str=sta_str+"2"
            continue
        if(cha=='D' or cha=='E' or cha=='F' or cha=='3'):
            sta_str=sta_str+"3"
            continue
        if(cha=='G' or cha=='H' or cha=='I' or cha=='4'):
            sta_str=sta_str+"4"
            continue
        if(cha=='J' or cha=='K' or cha=='L' or cha=='5'):
            sta_str=sta_str+"5"
            continue
        if(cha=='M' or cha=='N' or cha=='O' or cha=='6'):
            sta_str=sta_str+"6"
            continue
        if(cha=='P' or cha=='R' or cha=='S' or cha=='7'):
            sta_str=sta_str+"7"
            continue
        if(cha=='T' or cha=='U' or cha=='V' or cha=='8'):
            sta_str=sta_str+"8"
            continue
        if(cha=='W' or cha=='X' or cha=='Y' or cha=='9'):
            sta_str=sta_str+"9"
            continue
    return sta_str
    

def count_words(list_word):
    dict_num={}
    for item in list_word:
        if item in dict_num:
            dict_num[item]=dict_num[item]+1
        else:
            dict_num[item]=1      
    return dict_num  

def output(dict_num):
    dict_num0=dict_num.copy()
    for key in dict_num:
        if(dict_num[key]==1):
            del dict_num0[key]
    if(len(dict_num0)==0):
        print("No duplicates.")
    else:
        dict_num1=sorted(dict_num0.items(), key=lambda dict_num0:dict_num0[0])
        for item in dict_num1:
            print(item[0][:3]+"-"+item[0][3:],item[1])


list_standard=[]
for item in list_convenient:
    list_standard.append(ConvenirntToStandard(item))

output(count_words(list_standard))

 

你可能感兴趣的:(蓝桥杯python备战练习题,python)