Թաքցված խնդիր
|Այս խնդիրը թաքցված է խմբագրական խրհրդի անդամի կողմից քանի որ կամ այն ոչ ճիշտ լեզվով է գրված,|կամ թեստային տվյալներն են սխալ, կամ խնդրի ձևակերպումը պարզ չէ։|

ACM_0110 - JUMBLE MATCH

   For the purpose of this problem, a word matches a pattern if a substring of the word matches the pattern. A pattern can contain letters (which should be matched explicitly) and underscores (which match any single letter). Finally, a pattern is considered matched if any jumble (permutation) of the pattern characters matches.

   For example, the pattern cat matches words such as cat, scat, and cater because cat is a substring of the word. However, the pattern also matches words that contain permutations of cat as a substring, such as tacit, latch, and fact. And the pattern cat_ would match any word that contains a 4-character substring that is some permutation of the letters c, a, t, and any other letter, which would therefor match words such as track, cant, or crate.

   Your task is to write a program that searches for a jumble match in a set of input words.

Input

   Input will consist of specifications for a series of tests. Information for each test begins with a line containing a single string of length 1 <= n < 100 that specifies the pattern to search for. A pattern string consisting of a single dot terminates the input.

   The lines following the pattern begin with an integer 1 <= n <= 10 that specifies the number of words on the line, followed by the words themselves, with a single space between items. Words are strings of alphabetic characters of length 1 < n < 20. A line with a word count of 0 ends the input for each test.

Output

   Output should consist of one line for each test comprising the test number (formatted as shown) followed by a single space and the number of words in the input set that match the pattern.

Examples

stdin

stdout

1

cat

10 act canto chest colt crest eject hutch scant tact track

10 bitch cat civet cotta cut evict notch stack tic tuc

2 cant chert

0

cat_

10 act canto chest colt crest eject hutch scant tact track

10 bitch cat civet cotta cut evict notch stack tic tuck

2 cant chert

0

c_t_

10 cat canto chest colt crest eject hutch scant tact track

10 bitch cat civet cotta cut evict notch stack tic tuck

2 cant chert

0

.

Test 1: 4

Test 2: 6

Test 3: 14


Ավելացրեց.Հրանտ Հովհաննիսյան
Ամսաթիվ.2014-01-29
Ժամանակի սահմանափակումը.1s
Ծրագրի տեքստի սահմանափակումը.50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Լեզուներ.Բոլորը բացի ASM32 ASM64 GAWK CLPS CLOJURE D ERL FSHARP FORTRAN GOSU HASK ICON ICK NEM NIM OBJC-CLANG PICO PIKE PYPY PYPY3 PY_NBC RUST SCM guile CHICKEN SED TCL WHITESPACE
Աղբյուրը.Australian Programming Contest 2013.F

© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.