欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

【笔试题目】58同城2020秋招测试开发

程序员文章站 2022-03-04 11:58:44
...

题目描述

输入单词,如head,apple,middle,end,hard统计出e或d字母结尾的单词

打印结果

{head=1, apple=1, middle=1, end=1, hard=1}
line = raw_input('')
values = line.split(',')
dict1={}
list1=[]
for i in values:
    if (i[-1]=='d'or i[-1]=='e') and i not in dict1.keys():
        dict1[i] = 1
        list1.append(i)
    elif (i[-1]=='d'or i[-1]=='e') and i in dict1.keys():
        dict1[i] += 1

str1=''

for i in list1:
    str1+='%s=%d, '% (i,dict1[i])
str2='{'+str1[:-2]+'}'
print str2

测试用例通过20%

题目描述2

找出重叠的字符串
如输入aabaabb
重叠的字符串有 aa aa bb
打印结果

a:4
b:2
str1=raw_input('')

dict1={}
list1=[]

index=0
temp_num=0
for i in str1:
    if index<len(str1)-1:
        if i not in dict1.keys() and str1[index+1]==i :
            dict1[i] = 1
            index+=1
        elif i in dict1.keys() and str1[index+1]==i :
            dict1[i] += 1
            index += 1
        elif i in dict1.keys() and str1[index-1]==i :
            dict1[i] += 1
            index += 1
        else:
            index += 1
    else:
        if i in dict1.keys() and str1[index - 1] == i:
            dict1[i] += 1

# print dict1.iteritems()
dict2 = sorted(dict1.iteritems(), key=lambda d: d[1],reverse = True)

for x in dict2:
    if x[1]>1:
        print x[0]+':'+str(x[1])