10.31.2024刷华为OD C题型

文章目录

10.24.2024刷华为OD C题型(四) -

HJ26

HJ27

python 复制代码
def get_dict(str1: str):
    dic_0 = {}
    for ch in str1:
        if ch not in dic_0:
            dic_0[ch] = 1
        else:
            dic_0[ch] += 1
    return dic_0

temp = input().split()
n = int(temp[0])
list = []
for i in range(n):
    list.append(temp[i + 1])
str_comp = temp[-2]
k = int(temp[-1])

res_list = []

dic_comp = get_dict(str_comp)



for i in range(n):
    if get_dict(list[i]) != dic_comp:
        continue
    if list[i] == str_comp:
        continue
    else:
        res_list.append(list[i])
# print(res_list)
res_list = sorted(res_list)
print(len(res_list))
if len(res_list) >= k:
    print(res_list[k - 1])

参考答案:

语法知识记录

  • 获取输入参数可以用list的【:】
  • 比较单词字符是否一样,可以直接从list里抽出来,然后用sorted
相关推荐
Emilin Amy5 分钟前
【C++】【STL算法】那些STL算法替代的循环
开发语言·c++·算法·ros1/2
遇印记9 分钟前
蓝桥java求最大公约数
java·开发语言
ONExiaobaijs11 分钟前
【无标题】
java·开发语言·spring·maven·程序员创富
IMPYLH16 分钟前
Lua 的 String(字符串) 模块
开发语言·笔记·单元测试·lua
qeen8718 分钟前
【数据结构】顺序表的详细解析及其简单通讯录实现
c语言·数据结构·学习
符哥200820 分钟前
Mybatis和Mybatis-plus区别
java·开发语言·mybatis
企业对冲系统官26 分钟前
期货与期权一体化平台风险收益评估方法与模型实现
运维·服务器·开发语言·数据库·python·自动化
ceclar12335 分钟前
C++使用numeric
开发语言·c++
zh_xuan36 分钟前
kotlin函数的一些用法
开发语言·kotlin
编程大师哥1 小时前
如何在C++中使用Redis的事务功能?
开发语言·c++·redis