华为OD机试真题-万能字符单词拼写-2023年OD统一考试(C卷)---Python3--开源

题目:

考察内容:

str.repalce(old, new, 1); flag

代码:

python 复制代码
"""
题目分析:
没有掌握,输出为0
输入:
words的个数, N int
每个字符串元素

输出:
词汇表words中掌握的单词个数
4
cat
bt
hat
tree
atach??

4
ax
cae
hcae
ahe
atach?

1
tree
atach??
思路:

"""
N = int(input())
words_list = list()
words_set = set()
for _ in range(N):
    str_temp = input()
    words_list.append(str_temp)

glossary = input()
# 先把替换的字母求出来,再遍历,去重

res_sum = 0
for words in words_list:
    # 每遍历一个新的word, 词汇表重新赋值
    temp_glossary = glossary
    flag = False
    for word in words:
        if word in temp_glossary:
            temp_glossary = temp_glossary.replace(word, "", 1)
        elif "?" in temp_glossary:
            temp_glossary = temp_glossary.replace("?", "", 1)
        else:
            flag = True
    if not flag:
        res_sum += 1

print(res_sum)
相关推荐
喜欢喝果茶.4 分钟前
QOverload<参数列表>::of(&函数名)信号槽
开发语言·qt
亓才孓5 分钟前
[Class类的应用]反射的理解
开发语言·python
努力学编程呀(๑•ี_เ•ี๑)5 分钟前
【在 IntelliJ IDEA 中切换项目 JDK 版本】
java·开发语言·intellij-idea
island131426 分钟前
CANN GE(图引擎)深度解析:计算图优化管线、内存静态规划与异构任务的 Stream 调度机制
开发语言·人工智能·深度学习·神经网络
坚持就完事了30 分钟前
Java中的集合
java·开发语言
魔芋红茶34 分钟前
Python 项目版本控制
开发语言·python
云小逸1 小时前
【nmap源码解析】Nmap OS识别核心模块深度解析:osscan2.cc源码剖析(1)
开发语言·网络·学习·nmap
冰暮流星1 小时前
javascript之二重循环练习
开发语言·javascript·数据库
风指引着方向1 小时前
自定义算子开发入门:基于 CANN op-plugin 的扩展实践
开发语言
Fairy要carry1 小时前
面试-GRPO强化学习
开发语言·人工智能