华为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)
相关推荐
m0_531237171 分钟前
C语言-结构体进阶
c语言·开发语言
遨游xyz2 分钟前
BM算法(Boyer-Moore)
开发语言·python
独自破碎E13 分钟前
BISHI66 子数列求积
android·java·开发语言
devmoon17 分钟前
从 0 到 1 实现两条独立区块链Parachain的跨链通信能力之实操指南
开发语言·rust·区块链·信息与通信·polkadot
清水白石00825 分钟前
依赖注入的优雅:不用框架,在 Python 中实现轻量级依赖注入
开发语言·python
游乐码27 分钟前
c#里氏替换
开发语言·c#
未来之窗软件服务29 分钟前
AI人工智能(十二)C# 运行sensevoice onnx—东方仙盟练气期
开发语言·人工智能·c#·仙盟创梦ide·东方仙盟
weixin_4404016931 分钟前
Python数据分析-合并清洗与转换(concat+lambda函数+apply+删除drop/替换数据replace)
开发语言·python·数据分析
Dxy123931021632 分钟前
Python如果遇见乱码可以通过二进制判断是什么编码吗?
开发语言·python
TTBIGDATA39 分钟前
【Atlas】Atlas 搜索时报 `__AtlasUserProfile` 不存在导致事务回滚
开发语言·python·ambari·kerberos·ranger·atlas·bigtop