华为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)
相关推荐
神仙别闹13 分钟前
基于C++ 实现 BP 神经网络
开发语言·c++·神经网络
疯狂成瘾者29 分钟前
Java 集合 LinkedList 详解:链表结构、常用方法和队列使用
java·开发语言·链表
云梦泽࿐้34 分钟前
变量与数据类型:Python世界的基石
开发语言·python
QK_0035 分钟前
C语言 static 关键字三大作用
c语言·开发语言
开发小能手-roy41 分钟前
Lambda表达式性能陷阱:避坑指南与JIT编译优化分析
开发语言·python
爱读书的小胖1 小时前
无偿分享ChatGPT Image 2画图网页与并发绘图python程序【Ai绘图】
开发语言·python·chatgpt
我命由我123451 小时前
Jetpack Room - Room 查询返回列表无需判空、LIKE 关键字
android·java·开发语言·java-ee·android jetpack·android-studio·android runtime
goodluckyaa1 小时前
Warp shuffle函数
开发语言
j7~1 小时前
【C++】STL--Vector容器--拆析解剖Vector的实现以及Vector的底层详解(1)
开发语言·c++·vector·迭代器失效·迭代器的使用
xxwl5851 小时前
Python语言初步认识(1)
开发语言·python·学习