华为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)
相关推荐
CheungChunChiu几秒前
从 Rust 到 Flutter:嵌入式图形与构建工具全景指南
开发语言·flutter·rust
满天星83035776 分钟前
【C++】智能指针
c语言·开发语言·c++·visual studio
hj104335 分钟前
php上传企业微信附件的方法
开发语言·php·企业微信
起予者汝也1 小时前
Python基础入门
开发语言·python
芯联智造2 小时前
【stm32协议外设篇】- SU03T 智能语音模块
c语言·开发语言·stm32·单片机·嵌入式硬件
川石课堂软件测试2 小时前
Python | 高阶函数基本应用及Decorator装饰器
android·开发语言·数据库·python·功能测试·mysql·单元测试
lqqjuly2 小时前
Matlab2025a实现双目相机标定~业余版
开发语言·matlab·相机标定·双目相机
Brianna Home2 小时前
现代C++:从性能泥潭到AI基石
开发语言·c++·算法
2301_796512522 小时前
Rust编程学习 - 自动解引用的用处,如何进行“解引用”(Deref) 是“取引用”(Ref) 的反操作
开发语言·学习·rust
qq19257230272 小时前
c++特性
开发语言·c++·算法