题解 | #查找兄弟单词#
查找兄弟单词
http://www.nowcoder.com/practice/03ba8aeeef73400ca7a37a5f3370fe68
python思路:
while True:
try:
a = input()
b = a.split(" ") #字符串分解为列表
k = int(b[-1]) #获取k值
target_str = b[-2] #获取目标字符串
bro_list = b[1:-2] #获取筛选列表
res_list=[] #兄弟字符串列表
for i in bro_list:
if sorted(target_str) == sorted(i) and target_str!=i: #两字符串不相等并且排序后不相等符合条件 res_list.append(i)
print(len(res_list))
print((sorted(res_list))[k-1])
except:
break