Wildcard (Large)
Time limit5sMemory limit512 MB
Given two filenames A and B, find the shortest star pattern that matches A but not B, breaking ties by fewer stars then lexicographic order.
- Level
Hard8 of 10
- Topics
- Dynamic programming, String matching, BFS
- Solved
- No attempts yet
Problem
Many operating systems let you use * (an asterisk) as a wildcard when you name a file. A * matches any string, and the empty string counts.
Wildcards are often used to name several files at once, and they also make naming a single file easier. Suppose you want to name the file pascalisamazing. If it is the only file matching the pattern pascal*, then that pattern names pascalisamazing, and pascal* is much shorter to type.
Given two file names, find the shortest pattern that matches the first name but not the second.
A pattern is a string of lowercase letters and *. The pattern matches a name if you can replace each * in it with some string, possibly the empty string, and get exactly that name.
Input
The first line has the number of test cases . Each test case takes two lines: the first file name on one line and the second file name on the next. File names consist of lowercase letters only.
Constraints
- and are different strings
- and are each 1 to 50 characters long
Output
For each test case print one line in this format.
Case #X: Y
is the test case number and is the shortest pattern that matches but not . If several patterns share the shortest length, print the one with the fewest asterisks. If several still remain, print the smallest one in lexicographic order. Compare characters by their ASCII codes, where the code 42 of * is smaller than any lowercase letter.