#P7064. [NWRRC 2014] Expression
[NWRRC 2014] Expression
题目描述
In computing, regular expressions is a powerful tool for text search and string matching. In this problem a simplified version of regular expressions is used:
-
An empty string
is a regular expression, only the empty string matches it. -
A single lowercase letter
cis a regular expression, a string consisting of a single letter matches it. -
A dot
.is a regular expression, a string consisting of any single letter matches it. -
Alternation: if and are regular expressions then
(α|β)is a regular expression, a string matches it only if matches or matches . -
Concatenation: if and are regular expressions then
(αβ)is a regular expression, a string matches it only ifxy, matches and matches . -
Kleene star: if is regular expression then
(α∗)is a regular expression, a string matches it only if is empty orxy, is nonempty and matches and matches In other words, consists of zero or more strings, each of them matches
Parentheses can be omitted, in this problem Kleene star has the highest priority, concatenation has medium priority and alternation has lowest priority. Thus abc*|de means (ab(c*))|(de).
For example, string abcabcab matches a(bc|a)*ab, but string abcbab does not.
Your task is to find the shortest string that matches the given regular expression and contains the given substring .
输入格式
The first line of the input file contains the regular expression . The second line of the input file contains the substring .
String consists of lowercase English letters. Expression consists of lowercase English letters and special characters: dots (.), parentheses (() and ()), pipes (|), and asterisks (*).
输出格式
Output the shortest possible string that both matches and contains as substring. If there are no such strings, output NO.
The string should contain only lowercase English letters.
a.*b
bab
abab
(ab)*
bb
NO
提示
Time limit: 10 s, Memory limit: 256 MB.