华为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)
相关推荐
小菱形_5 分钟前
【C#】LINQ
开发语言·c#·linq
爱吃大芒果7 分钟前
Flutter 基础组件详解:Text、Image、Button 使用技巧
开发语言·javascript·flutter·华为·ecmascript·harmonyos
Hominid⁺15 分钟前
深度解析:C 语言的 8 个翻译阶段与 GCC 编译全流程
c语言·开发语言
steins_甲乙20 分钟前
C++并发编程
开发语言·c++
曹牧23 分钟前
C#:foreach
开发语言·c#
计算机学姐26 分钟前
基于Python的商场停车管理系统【2026最新】
开发语言·vue.js·后端·python·mysql·django·flask
小猪快跑爱摄影27 分钟前
【AutoCad 2025】【Python】零基础教程(一)——简单示例
开发语言·python
AI云原生31 分钟前
在 openEuler 上使用 x86_64 环境编译 ARM64 应用的完整实践
java·运维·开发语言·jvm·开源·开源软件·开源协议
曹牧32 分钟前
C#中解析JSON数组
开发语言·c#·json
while(1){yan}1 小时前
多线程CAS八股文
java·开发语言·面试