华为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)
相关推荐
彷徨而立2 分钟前
【C/C++】创建文件夹
c语言·开发语言·c++
User_芊芊君子6 分钟前
Java异步编程:提升性能的实战秘籍
java·开发语言·python
小猫咪怎么会有坏心思呢11 分钟前
华为OD机考-英文输入法-逻辑分析(JAVA 2025B卷)
java·开发语言·华为od
虾球xz21 分钟前
游戏引擎学习第315天:取消排序键的反向顺序
开发语言·c++·学习·游戏引擎
martian66536 分钟前
达梦数据库中无效触发器的排查与解决方案指南
开发语言·数据库
无名之逆36 分钟前
Junior Year Self-Study Notes My Journey with the Hyperlane Framework
java·开发语言·前端·spring boot·后端·rust·编程
大白爱琴1 小时前
C++ 精简知识点
开发语言·c++
YuTaoShao1 小时前
Java八股文——JVM「垃圾回收篇」
java·开发语言·jvm
蓝婷儿1 小时前
Python 爬虫入门 Day 1 - 网络请求与网页结构基础
开发语言·python·学习
KIDAKN1 小时前
抽象类和接口的区别
java·开发语言