<PREV Problem:
NEXT>
Solved by 165 users: ...
 < 
 < 
 < 
 < 
 < 
 < 
 < 
 < 
 < 
 < 

Two regular expressions

Time limit = 2 second(s)

You are given two regular expressions R1 and R2 and should find minimal string S matching both. String consists of capital latin letters A..Z. Regular expression is word consisting of A..Z and * ? symbols. The symbol * corresponds to any word or empty word. The symbol ? corresponds to one letter.

Input Two lines with regular expressions R1 and R2, each line has less than 500 characters.

Output String S — one of the strings with minimal length matching both regular expressions. If string matching R1 and R2 does not exist, then output #.

Input#1
?A*BCD
*ABC?
Output#1
AABCD

Input#2
?*A*?
???
Output#2
AAA

Input#3
B*A*A
?B?
Output#3
#

Author:
From the book "National features of programming problems" 29 September 2003

<PREV | Problem set | Search related messages | NEXT>


© acm.mipt DevGroup
The page was generated in 210ms

SW soft NIX
ID = 54.81.197.127