华为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)
相关推荐
代码AI弗森6 小时前
Git Bash 与 PowerShell:定位差异、使用场景与选择建议
开发语言·git·bash
代码游侠6 小时前
C语言核心概念复习(一)
c语言·开发语言·c++·笔记·学习
蜕变的土豆6 小时前
grpc-通关速成
开发语言·c++
-To be number.wan6 小时前
Python数据分析:英国电商销售数据实战
开发语言·python·数据分析
xb11326 小时前
C#生产者-消费者模式
开发语言·c#
电商API&Tina6 小时前
乐天平台 (Rakuten) 数据采集指南
大数据·开发语言·数据库·oracle·json
zhougl9966 小时前
Java内部类详解
java·开发语言
Grassto6 小时前
11 Go Module 缓存机制详解
开发语言·缓存·golang·go·go module
代码游侠7 小时前
学习笔记——Linux内核与嵌入式开发3
开发语言·arm开发·c++·学习
怎么没有名字注册了啊7 小时前
C++ 进制转换
开发语言·c++