OD C卷 - 掌握单词的个数

掌握单词的个数(100)

  • 有一个字符串数组words 和 一个字符串chars,假如可以用chars中的字母拼写出words中的某个单词,就认为掌握了这个单词;
  • words中的单词仅由a-z小写字母组成,如“abc”;
  • chars 由a-z小写字母、“?”组成,“?”表示万能字符,可以当做任意一个英文字母使用;每次拼写时,chars中的每个字母和万能字符都只能用一次;
  • 输出words数组中,已经掌握的单词个数,没有掌握任何单词则输出0;

输入描述:
输入words数组的长度;
依次输入每个单词;
输入字符串chars;
输出描述:
输出掌握的单词数,words数组长度在【1,100】
words[i], chars 长度均在【1,100】

示例1
输入:
4
cat
bt
hat
tree
atach??
输出:
3

示例2
输入:
3
hello
word
cloud
welldonehohneyr
输出:
2

示例3
输入:
3
apple
car
window
welldoneapplec?
输出:
2


n = int(input())
words = []
for i in range(n):
    words.append(input())
chars = input()
char_count_map = [0 for i in range(26)]
maigc_char_count = 0
j=0
while(True):
    if(j>=len(chars)):
        break
    else :
        if(chars[j] == '?'):
            maigc_char_count +=1
        else :
            char_count_map[ord(chars[j])-ord('a')] += 1
    j+=1
 
 
output_count = 0
i=0
while(True):
    if(i>=n):
        print(output_count)
        break
    else :
        word_count_map = [0 for i in range(26)]
        for k in range(len(words[i])):
            word_count_map[ord(words[i][k])-ord('a')]+=1
        
 
        flag = True
        temp_count = maigc_char_count
        for k in range(26):
            if (word_count_map[k] - char_count_map[k] >0):
                temp_count -= word_count_map[k] - char_count_map[k]
                if(temp_count < 0) :
                    flag = False
                    break
        if (flag) :
            output_count+=1
    i+=1
  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

laufing

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值