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
相关推荐
似水明俊德5 小时前
02-C#.Net-反射-面试题
开发语言·面试·职场和发展·c#·.net
爱编码的小八嘎6 小时前
C语言完美演绎4-7
c语言
Thera7776 小时前
C++ 高性能时间轮定时器:从单例设计到 Linux timerfd 深度优化
linux·开发语言·c++
炘爚7 小时前
C语言(文件操作)
c语言·开发语言
阿蒙Amon7 小时前
C#常用类库-详解SerialPort
开发语言·c#
凸头7 小时前
CompletableFuture 与 Future 对比与实战示例
java·开发语言
wuqingshun3141597 小时前
线程安全需要保证几个基本特征
java·开发语言·jvm
Moksha2627 小时前
5G、VoNR基本概念
开发语言·5g·php
jzlhll1238 小时前
kotlin Flow first() last()总结
开发语言·前端·kotlin
W.D.小糊涂8 小时前
gpu服务器安装windows+ubuntu24.04双系统
c语言·开发语言·数据库