Orange Boy/Red Girl/Legendary Grandmeow Can You Solve It Out?
思考题 for grand contest
Orange Boy(Monk.eyk.ing),Red girl(Mack.erel.pike) and their cat LGM(Legendary.Grand.Meow) are a happy family. But in fact, they are the heroes that is helping the world in silent.
One day, the earth is under the attack by the Implementation Dragon. So the three went off to divide and conquer.
The three must fight together to solve the OI question by the I.D.(Implementation Dragon)
As we know, a Regex is a kind of pattern to match strings. The pattern can be seen as many subpatterns. In this problem, we will consider a easy problem.
Patterns could be:
 "a"  any lowercase letter. This will match the exactly character. For example, Regex "a" will only match string "a"
 "ab"  match a or b. For example, Regex "yp" will match "y" or "p"

"[abc]"  match exactly one in the bracket. eg. "[abc]" will match "a" or "b" or "c"

"."  a dot will match any character. eg."." will match "a" "b" "c"... "z"

"a"  may match 0 or more times. eg. "a" will match ""(empty string) "a" "aa" "aaa" ... "aaaaaa" etc

"()"  to make things altogether. eg."(abc)(def)" will match "abc" or "def"
All together, for example, "https" will match "http" "https" "httpss" ... etc
"([abc])yp" will match any string consisted only of abc and "y" and "p".
Now you are going to help one hero.
Helping LGM
You are given a Regex pattern. Your task is to find out if it is a valid pattern.
"abc" answer is YES
"(xx*" answer is NO
Helping Orange Boy
You are given a Regex pattern. Your task is to find out any string that matches this pattern.
"([abc]*)yp" Output:"abc"
Helping Red Girl
You are given a Regex pattern and a string. Your task is to find out whether the string matches the pattern.
"([abc]*)yp" and "y" answer is YES
"x" and "y" answer is NO
Constriants
The string consists of only lowercase letters and necessary special characters. The length does not exceed 50.
Solution By XGN
Problem is too easy to give out my answer. Use Python and Java will be useful.
版权声明：
作者：XGN
链接：https://blog.hellholestudios.top/archives/227
来源：Hell Hole Studios Blog
文章版权归作者所有，未经允许请勿转载。
共有 0 条评论