华为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)
相关推荐
猷咪22 分钟前
C++基础
开发语言·c++
IT·小灰灰24 分钟前
30行PHP,利用硅基流动API,网页客服瞬间上线
开发语言·人工智能·aigc·php
快点好好学习吧25 分钟前
phpize 依赖 php-config 获取 PHP 信息的庖丁解牛
android·开发语言·php
秦老师Q26 分钟前
php入门教程(超详细,一篇就够了!!!)
开发语言·mysql·php·db
烟锁池塘柳026 分钟前
解决Google Scholar “We‘re sorry... but your computer or network may be sending automated queries.”的问题
开发语言
是誰萆微了承諾26 分钟前
php 对接deepseek
android·开发语言·php
2601_9498683630 分钟前
Flutter for OpenHarmony 电子合同签署App实战 - 已签合同实现
java·开发语言·flutter
星火开发设计44 分钟前
类型别名 typedef:让复杂类型更简洁
开发语言·c++·学习·算法·函数·知识
qq_177767371 小时前
React Native鸿蒙跨平台数据使用监控应用技术,通过setInterval每5秒更新一次数据使用情况和套餐使用情况,模拟了真实应用中的数据监控场景
开发语言·前端·javascript·react native·react.js·ecmascript·harmonyos
一匹电信狗1 小时前
【LeetCode_21】合并两个有序链表
c语言·开发语言·数据结构·c++·算法·leetcode·stl