cswork / OA打开练习工作台

Susquehanna International GroupOA #3

Word Skeletons (- Wildcard Match)

简单可在线判题

考点(AI 标注)字符串哈希计数

You are given a lowercase target word and a list of skeletons of the same length. Skeletons contain only lowercase letters and hyphens. Each hyphen can be replaced with any letter that already appears in that original skeleton; copying does not consume letters, so the same letter can be reused for multiple hyphens. All other positions stay unchanged. Return the original skeletons that can become word, keeping the input order and duplicates; return an empty list if none match.

输入格式

The first line contains word, the second line contains the number of skeletons m, followed by m lines, each with one skeleton. 1≤word length≤100, 1≤m≤100, and every skeleton has the same length as word. word contains only a..z; skeletons contain only a..z and -.

输出格式

The first line is the number of matches, followed by the matching original skeletons, one per line. If there is no match, output only 0, and do not output the word after replacement.

样例 1

输入:

hello
4
he-lo
he--o
-ell-
hello

输出:

2
he-lo
hello

样例 2

输入:

aaaa
4
a---
----
a---
aaaa

输出:

3
a---
a---
aaaa

样例 3

输入:

ab
3
--
aa
-b

输出:

0

样例说明

Original OCR008 mistakenly wrote he-o, while 009 clearly shows he--o (two hyphens and no l); this site fixes it according to 009. Of the four original skeletons for hello, he-lo, he--o, -ell-, and hello, only he-lo and hello qualify. The original l stays in place and can be copied to fill hyphens; the original text has no consumption or usage limit. aaaa can be obtained from a--- by repeated copying, and a skeleton made entirely of hyphens fails because it has no source letter.