Huadian North Wind Blows
Key laboratory of cognitive computing and application, Tianjin University
Date: 2015/10/14
Topic Description:
Please implement a function to match the include '. ' and ' regular expressions. The characters in the pattern '. ' Represents any one character, and ' means that the preceding character can appear any time (including 0 times). In this point, a match is a string that matches all the characters of the entire pattern. For example, the string "AAA" matches the schema "A.A" and "ab*ac*a", but does not match "aa.a" and "Ab*a"
Analytical:
The problem with Microsoft is to find out how many sequential Fibonacci numbers in an array are similar problems. There are special circumstances that need to be considered ". *a", and there are other details to consider.
Code:
Class Solution {Public:bool match (char* str, char* pattern) {if (str[0]== ' ") {if (
pattern[0]== ' ") return true;
if (pattern[1]== ' * ') return match (str,pattern+2);
return false;
if (pattern[0]== ') return false;
else {if (pattern[1]== ' * ') {bool result=false; result=result| |
Match (STR,PATTERN+2);
if (result) return true; while (str[0]==pattern[0]| | ((pattern[0]== '. ') && (str[0]!= ')) {result=result| |
Match (++STR,PATTERN+2);
if (result) return true;
return result; if (pattern[0]== '. ') | |
(Str[0]==pattern[0])
{return match (++str,++pattern); } returnFalse }
}
};