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

题目描述

输入单词,如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])
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Bug 挖掘机

支持洋子

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值