#include<iostream.h> 
      using namespace std;
      int main() 
      {
          //Initialize the variables.
          string wild = "Prep*nsta",str="Prepinsta";
          //Accept the inputs.
          cout<<"String containing wild characters: ";
          cout<<wild<<endl;
          cout<<"String to be matched: ";
          cout<<str<<endl;
          bool TRUE=true,FALSE=false;
          bool check[wild.length()+1][str.length()+1];
          check[0][0]=TRUE;
          for(int i=1;i<=str.length();i++)
             check[0][i]=FALSE;
          for(int i=1;i<=wild.length();i++)
              if(wild[i-1] == '*')//Checking for wild characters.
                  check[i][0]=check[i-1][0];
          else
              check[i][0]=FALSE;
          for(int i=1;i<=wild.length();i++)
          {
              for(int j=1;j<=wild.length();j++)
              {
                  if(wild[i-1] == str[j-1])
                      check[i][j]=check[i-1][j-1];
                  else if(wild[i-1] == '?')//Checking for wild character '?'.
                      check[i][j]=check[i-1][j-1];
                  else if(wild[i-1] == '*')//Checking for wild character '*'.
                      check[i][j]=check[i-1][j]||check[i][j-1];
                  else
                     check[i][j] =FALSE;
              }
          }
          //Printing result.
          if(check[wild.length()][str.length()])
              cout<<"TRUE";
          else
              cout<<"FALSE";
      }
      
      Cpp language logo

      String contains wild characters

      0

      0

      avatar
      drzyadav

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.