https://leetcode-cn.com/problems/regular-expression-matching/
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
#pragma warning(disable:4996)
string str1, str2;
const int maxn = 200;
bool dp[maxn][maxn] = {false};
int strLen1;
int strLen2;
bool characterMatch(int i,int j)
{
if (i < 0)
{
return false;
}
if (str2[j] == '.')
{
return true;
}
return str1[i] == str2[j];
}
void match()
{
//初始化dp
fill(dp[0], dp[0] + maxn * maxn, false);
//初始条件
dp[0][0] = true;
//边界
int strLen1 = str1.size();
int strLen2 = str2.size();
//str1是被匹配的字符串 str2是正则化字符串
for (int i = 0; i <= strLen1; i++)
{
for (int j = 1; j <= strLen2; j++)
{
if (str2[j-1] == '*')
{
if (characterMatch(i - 1, j - 2))
{
dp[i][j] = dp[i - 1][j];
}
else
{
dp[i][j] = dp[i][j - 2];
}
}
else
{
if (characterMatch(i - 1, j - 1))
{
dp[i][j] = dp[i - 1][j - 1];
}
}
}
}
}
int main()
{
freopen("data.txt", "r", stdin);
freopen("result.txt", "w", stdout);
cin >> str1 >> str2;
match();
int strLen1 = str1.size();
int strLen2 = str2.size();
//cout << dp[strLen1][strLen2];
if (dp[strLen1][strLen2] == true)
{
cout << "true";
}
}