#include<bits/stdc++.h>
using namespace std;
int main()
{
string a;
string b;
getline(cin,a);
getline(cin,b);
int a_len=a.length();
int b_len=b.length();
int dp[a_len][b_len];
for(int i=1;i<=b.length();i++)
{
if(b[i-1]==ββ)
{
dp[0][i]=1;
}
else
{
dp[0][i]=0;
}
}
for(int i=0;i<=a.length();i++)
{
dp[i][0]=0;
}
dp[0][0]=1;
for(int i=1;i<=a.length();i++)
{
for(int j=1;j<=b.length();j++)
{
if(b[j-1]==β?β|| b[j-1]==a[i-1])
{
dp[i][j]=dp[i-1][j-1];
}
else if(b[j-1]==ββ)
{
if(dp[i-1][j]==1||dp[i][j-1]==1)
{
dp[i][j]=1;
}
else
{
dp[i][j]=0;
}
}
else
{
dp[i][j]=0;
}
}
}
//print dp array
// for(int i=0;i<=a_len;i++)
// {
// for(int j=0;j<=b_len;j++)
// {
// cout<<dp[i][j]<<" ";
// }
// cout<<endl;
// }
if(dp[a_len][b_len]==1)
{
cout<<βMATCHEDβ;
}
else
{
cout<<βNOT MATCHEDβ;
}
return 0;
}
Wildcard matching why is this code giving run time error
Hello @praritv1,
There are two mistakes in your code.
I have corrected them all:
Refer to comments for better understanding.
Hope, this would help.
Give a like if you are satisfied.