华为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)
相关推荐
Macbethad1 小时前
自动化测试技术报告
开发语言·lua
不会画画的画师1 小时前
Go开发指南:io/ioutil包应用和迁移指南
开发语言·后端·golang
2503_928411561 小时前
12.22 wxml语法
开发语言·前端·javascript
5980354151 小时前
【java工具类】小数、整数转中文大写
android·java·开发语言
JIngJaneIL1 小时前
基于java + vue个人博客系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot
吃喝不愁霸王餐APP开发者1 小时前
Java后端服务在对接全国性霸王餐API时的多数据中心部署与就近调用策略
java·开发语言
froginwe112 小时前
jQuery UI 实例
开发语言
这周也會开心2 小时前
128陷阱,==与equals区别
java·开发语言
kaikaile19952 小时前
matlab基于人工势场法的路径规划
开发语言·matlab
沙漠豪2 小时前
提取PDF发票信息的Python脚本
开发语言·python·pdf