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
相关推荐
014-code4 小时前
订单超时取消与库存回滚的完整实现(延迟任务 + 状态机)
java·开发语言
lly2024064 小时前
组合模式(Composite Pattern)
开发语言
游乐码5 小时前
c#泛型约束
开发语言·c#
Dontla5 小时前
go语言Windows安装教程(安装go安装Golang安装)(GOPATH、Go Modules)
开发语言·windows·golang
chushiyunen5 小时前
python rest请求、requests
开发语言·python
铁东博客5 小时前
Go实现周易大衍筮法三变取爻
开发语言·后端·golang
baidu_huihui5 小时前
在 CentOS 9 上安装 pip(Python 的包管理工具)
开发语言·python·pip
南 阳5 小时前
Python从入门到精通day63
开发语言·python
lbb 小魔仙5 小时前
Python_RAG知识库问答系统实战指南
开发语言·python
weixin_446023565 小时前
C语言:面向过程、应用底层开发、跨平台的通用程序设计语言
c语言·跨平台·数据类型·底层开发·面向过程