牛客华为机试HJ27
作者:互联网
1. 题目描述
2. Solution
1、思路:
先遍历所有的words,找出兄弟单词word,判定方法: word != key 且 排序后相等(或者计数后字母个数相等)
2、代码实现
import sys
if sys.platform != "linux":
sys.stdin = open("input/HJ27.txt")
def solve(line):
data = line.strip().split()
n = int(data[0])
k = int(data[-1])
key = data[-2]
words = data[1:-2]
bro_words = [word for word in words if word != key and sorted(word) == sorted(key)]
print(len(bro_words))
bro_words.sort()
if k < len(bro_words):
print(bro_words[k - 1])
for line in sys.stdin:
solve(line)
标签:sys,word,key,bro,牛客,words,机试,data,HJ27 来源: https://www.cnblogs.com/junstat/p/16163643.html