华为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)
相关推荐
道法自然|~12 分钟前
【PHP】简单的脚本/扫描器拦截与重要文件保护
开发语言·爬虫·php
GoWjw24 分钟前
在C&C++中结构体的惯用方法
c语言·开发语言·c++
静心观复28 分钟前
Java 中,`1 << 1`
java·开发语言
Bruce_kaizy39 分钟前
c++单调数据结构————单调栈,单调队列
开发语言·数据结构·c++
阿坤带你走近大数据44 分钟前
Python基础知识-数据结构篇
开发语言·数据结构·python
froginwe1144 分钟前
AJAX 实时搜索:技术原理与实现方法
开发语言
发光小北1 小时前
SG-CAN (FD) NET-210(双通道 CAN (FD) 转以太网网关)特点与功能介绍
开发语言·网络·php
liangshanbo12151 小时前
深入理解 Model Context Protocol (MCP):从原理到实践
开发语言·qt·microsoft
于是我说2 小时前
前端JavaScript 项目中 获取当前页面滚动位置
开发语言·前端·javascript
2739920292 小时前
QT5使用QFtp
开发语言·qt