华为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 分钟前
线程和进程的区别和联系
java·开发语言·jvm
zzcufo23 分钟前
多邻国第五阶段第13部分
java·开发语言·数据库
37方寸31 分钟前
前端基础知识(JavaScript)
开发语言·前端·javascript
Whisper_Sy1 小时前
Flutter for OpenHarmony移动数据使用监管助手App实战 - 应用列表实现
android·开发语言·javascript·flutter·php
小CC吃豆子1 小时前
Python爬虫
开发语言·python
机器视觉知识推荐、就业指导1 小时前
Qt 6 所有 QML 类型(官方完整清单 · 原始索引版)
开发语言·qt
techdashen1 小时前
Rust OnceCell 深度解析:延迟初始化的优雅解决方案
开发语言·oracle·rust
少控科技2 小时前
QT新手日记033
开发语言·qt
王九思2 小时前
Java 内存分析工具 MAT
java·开发语言·安全
superman超哥2 小时前
Serde 的零成本抽象设计:深入理解 Rust 序列化框架的哲学
开发语言·rust·开发工具·编程语言·rust序列化