当前位置 : 主页 > 编程语言 > java >

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

来源:互联网 收集:自由互联 发布时间:2022-06-30
题目描述 输入单词,如​​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:

题目描述

输入单词,如​​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:2str1=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])


网友评论