编程介的小学生 2017-10-09 07:35 采纳率: 20.5%
浏览 818
已采纳

Wild Domains

Description

Consider a search engine that knows a number of sites. A site is described by a well-formed domain name which consists of two or more domain parts separated by dots such as www.sharif.edu. A domain part is a string of upper-case and lower-case alphabetic characters. For the rest of this description, we use the term domain name for well-formed domain name.

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.
Input

The first line of the input file contains a single integer t (1 <= t <= 10), the number of test cases, followed by the input data for each test case. Each test case consists of two lines, each containing a domain pattern. Each domain pattern is at most 255 characters long, and does not include any leading or trailing blank characters.
Output

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.
Sample Input

2
www.?.edu
?.edu
*.edu
yahoo.com
Sample Output

YES
NO

  • 写回答

2条回答 默认 最新

  • devmiao 2017-10-27 13:55
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法