【名词解释】
在一行上依次输入:
一个整数
代表字符串的个数;
个长度为
,仅由小写字母构成的字符串
;
一个长度为
,仅由小写字母构成的字符串
;
一个整数
代表要查找的第
小的兄弟单词的序号。
第一行输出一个整数,代表给定的
个字符串中,
的“兄弟单词”的数量;
第二行输出一个字符串,代表将给定的
个字符串中
的“兄弟单词”按字典序排序后的第
小兄弟单词。特别地,如果不存在,则不输出任何内容(完全省略第二行)。
3 abc bca cab abc 1
2 bca
在这个样例中,
的兄弟单词为
、
、
、
、
。其中,标橙色的两个字符串存在于所给定的
个字符串中。第
小的兄弟单词为
。
3 a aa aaa a 1
0
在这个样例中,按照定义,字符串
没有兄弟单词。
本题已于下方时间节点更新,请注意题解时效性:
1. 2025-05-30 更新题面。
2. 2024-12-29 更新题面。
words = input().split(" ")
n = int(words[0])
words_list = words[1:n+1]
x = words[-2]
k = int(words[-1])
result = []
for word in words_list:
if len(word) != len(x)&nbs***bsp;word == x:
pass
else:
for s in x:
if x.count(s)!=word.count(s):
break
else:
result.append(word)
print(len(result))
if len(result) >= k:
print(sorted(result)[k-1])
input_ = input().split() n = int(input_[0]) data = input_[1:n+1] x = input_[-2] k = int(input_[-1]) brothers = [] for each in data: if each != x and sorted(list(each)) == sorted(list(x)): brothers.append(each) print(len(brothers)) if k <= len(brothers): print(sorted(list(brothers))[k-1])
s = input().split() num = int(s[0]) def IsBro(s1, s2): if s1 != s2 and sorted(s1) == sorted(s2): return True else: return False numbro = 0 bro = [] for i in range(1, num + 1): if IsBro(s[i], s[num + 1]): numbro += 1 bro.append(s[i]) print(numbro) bro_sorted = sorted(bro) index = int(s[-1]) - 1 if index < len(bro_sorted): print(bro_sorted[index])
import sys s = input().split() n=int(s[0]) k=int(s[-1]) target = s[-2] lst =s[1:-2] lst1=[] num =0 for i in lst: if len(i) == len(target): if (sorted(list(target))==sorted(list(i))) and (i!=target): lst1.append(i) num+=1 print(num) lst = sorted(lst1) if k<=len(lst): print(lst[k-1])
def is_bro(word1, word2): if word1 == word2: return False j = False w_l1 = [] w_l2 = [] for i in word1: w_l1.append(i) for i in word2: w_l2.append(i) w_l1 = sorted(w_l1) w_l2 = sorted(w_l2) if w_l1 == w_l2: j = True return j shu_ru = input().split() m = int(shu_ru[0]) # d = shu_ru[1 : m + 1] # 单词待查找列表 x = shu_ru[m + 1] # 单词本身 k = int(shu_ru[m + 2]) # 找第k个字典序排序后的兄弟单词 bro = [] for word in d: if is_bro(x, word): bro.append(word) print(len(bro)) bro = sorted(bro) if k <= len(bro): print(bro[k - 1])
list_input = input().split() n = int(list_input[0]) x = list_input[-2] k = int(list_input[-1]) list_dict_in = list_input[1: -2] list_brother = [] for word in list_dict_in: if (word != x) and (sorted(word) == sorted(x)): list_brother.append(word) print(len(list_brother)) if k <= len(list_brother): list_brother.sort() print(list_brother[k-1])
inp = list(map(str, input().split())) n = int(inp[0]) k = int(inp[-1]) target_word = inp[-2] dic = inp[1:-2] def is_brother(word1, word2): return sorted(word1) == sorted(word2) and word1 != word2 def find_brother_words(word_list, target_word, k): brother_words = [word for word in word_list if is_brother(target_word, word)] brother_words.sort() if k <= len(brother_words): return len(brother_words), brother_words[k - 1] else: return len(brother_words), None count, result_word = find_brother_words(dic, target_word, k) print(count) if result_word != None: print(result_word)