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
相关推荐
侃侃_天下2 天前
最终的信号类
开发语言·c++·算法
echoarts2 天前
Rayon Rust中的数据并行库入门教程
开发语言·其他·算法·rust
Aomnitrix2 天前
知识管理新范式——cpolar+Wiki.js打造企业级分布式知识库
开发语言·javascript·分布式
每天回答3个问题2 天前
UE5C++编译遇到MSB3073
开发语言·c++·ue5
伍哥的传说2 天前
Vite Plugin PWA – 零配置构建现代渐进式Web应用
开发语言·前端·javascript·web app·pwa·service worker·workbox
小莞尔3 天前
【51单片机】【protues仿真】基于51单片机的篮球计时计分器系统
c语言·stm32·单片机·嵌入式硬件·51单片机
小莞尔3 天前
【51单片机】【protues仿真】 基于51单片机八路抢答器系统
c语言·开发语言·单片机·嵌入式硬件·51单片机
liujing102329293 天前
Day03_刷题niuke20250915
c语言
我是菜鸟0713号3 天前
Qt 中 OPC UA 通讯实战
开发语言·qt
JCBP_3 天前
QT(4)
开发语言·汇编·c++·qt·算法