To restrict a search to some specific sites, a user is allowed to use domain patterns in a search query. A domain pattern is similar to a domain name, except that it may contain arbitrary number of the following wildcards:
- Asterisk character (*) that matches a sequence of one or more
domain parts separated by dots,
- Question mark character (?) that matches at least one and at most
three domain parts separated by dots,
- Exclamation mark character (!) that matches at least three domain
parts separated by dots.
Note that if a wildcard character appears in a domain pattern, it should be separated from its surrounding domain parts (if any) by dots. For example www.?.edu, or *.edu are both valid domain patterns matching domain name www.sharif.edu.
Two domain patterns match if at least one domain name can be constructed matching both domain patterns. For example, the domain patterns www.?.edu and *.edu match, since both match the domain name www.xyz.edu. Note that the constructed domain name may be an arbitrary (yet not necessarily an existing) site. You are to write a program that given two domain patterns, determines whether the patterns match.
输入描述The first line of the input file contains a single intege
输出描述There should be one line per test case in the output file containing a single word YES or NO, depending on whether the two domain patterns in the test case match or not.
2 www.?.edu ?.edu *.edu yahoo.com