华为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 分钟前
Python入门实操:基础语法+爬虫入门+模块使用全指南
开发语言·网络·爬虫·python·安全·web
逻辑驱动的ken1 小时前
Java高频面试题:03
java·开发语言·面试·求职招聘·春招
噜噜大王_1 小时前
深入理解 C 语言内存操作函数:memcpy、memmove、memset、memcmp
c语言·开发语言
广师大-Wzx1 小时前
一篇文章看懂MySQL数据库(下)
java·开发语言·数据结构·数据库·windows·python·mysql
野生技术架构师1 小时前
Java NIO到底是个什么东西?
java·开发语言·nio
lolo大魔王2 小时前
Go语言的异常处理
开发语言·后端·golang
chh5633 小时前
C++--模版初阶
c语言·开发语言·c++·学习·算法
灼灼桃花夭3 小时前
js之阳历 → 农历(含时辰)转换函数
开发语言·前端·javascript
派大星酷3 小时前
Java 调用 Kimi API 实战:实现与大模型的简单对话
java·开发语言·ai编程
小李子呢02113 小时前
前端八股性能优化(1)---防抖和节流
开发语言·前端·javascript