掌握单词的个数(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