当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。
The game of Scrabble is played with tiles. A tile either has a single letter written on it, or it is blank. In the latter case, the tile may be used to represent a letter of your choice. On your turn, you arrange the tiles to form a word. Each tile may be used at most once, but not all tiles need to be used. Given several Scrabble tiles and a dictionary, determine how many words in the dictionary can be formed using the given Scrabble tiles.
The input test file will contain multiple test cases. In each test case, the first line contains a positive integer n ≤ 1000 indicating the number of words in the dictionary. The following n lines each contain a single string with between 1 and 7 uppercase letters, representing a word in the dictionary. No word will appear in the dictionary twice. The next line contains a single string giving the tiles you have available. It will contain only capital letters, representing tiles with that letter on it, and underscores, representing blank tiles. The string will contain between 1 and 7 characters, possibly including duplicate tiles. The end-of-file is marked by a test case with n = 0 and should not be processed.
For each test case, write a single line with the number of dictionary words that can be spelled with the given Scrabble tiles.
5 PROGRAM CONTEST PIZZA ZA PITA _PIZA 3 BANANAS CARROTS FIGS A__AA__ 0
3 2
In the first test case, PIZZA
, ZA
and PITA
can be spelled as PIZ_A
, ZA
and PI_A
. There are not enough letters to spell PROGRAM
or CONTEST
. In the second test case, BANANAS
and FIGS
can be spelled as _A_A_A_
and ____
. On the other hand, CARROTS
would require 6 blanks in addition to the A
.
时间上限 | 内存上限 |
1000 | 65536 |