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
相关推荐
冷雨夜中漫步7 小时前
Python快速入门(6)——for/if/while语句
开发语言·经验分享·笔记·python
HABuo8 小时前
【linux文件系统】磁盘结构&文件系统详谈
linux·运维·服务器·c语言·c++·ubuntu·centos
m0_736919109 小时前
C++代码风格检查工具
开发语言·c++·算法
2501_944934739 小时前
高职大数据技术专业,CDA和Python认证优先考哪个?
大数据·开发语言·python
黎雁·泠崖10 小时前
【魔法森林冒险】5/14 Allen类(三):任务进度与状态管理
java·开发语言
2301_7634724611 小时前
C++20概念(Concepts)入门指南
开发语言·c++·算法
TechWJ11 小时前
PyPTO编程范式深度解读:让NPU开发像写Python一样简单
开发语言·python·cann·pypto
lly20240611 小时前
C++ 文件和流
开发语言
m0_7066532311 小时前
分布式系统安全通信
开发语言·c++·算法
寻寻觅觅☆12 小时前
东华OJ-基础题-104-A == B ?(C++)
开发语言·c++