m250892
BAN USERIn below c++ code , for checking it you need to copy code and just run, without any change,
In input you put simple string as first string and pattern for second string, then program give output true or false
code:
#include<iostream>
#include<string.h>
using namespace std;
bool check(string s1,string s2)
{
int l1 =s1.length(),l2 = s2.length();
if(l1==0 && l2==0)
{
return true;
}
else if(l1==1 && l2==0)
{
return false;
}
else if(l1==0 && l2==1)
{
if((int)s2[0] > 96)
{
return false;
}
else
{
return true;
}
}
else if(l1==0 && l2>1)
{
if((int)s2[0] > 96)
{
return false;
}
else
{
return check(s1,s2.substr(1,l2));
}
}
if(l1==1 && l2==1)
{
if((int)s2[0] > 96)
{
if(s1[0]==s2[0])
{
return true;
}
else
{
return false;
}
}
else
{
return true;
}
}
int t = (int)s2[0];
if(t>96)
{
if(s1[0]==s2[0])
{
return check(s1.substr(1,l1), s2.substr(1,l2));
}
else
{
return false;
}
}
else if(t==42)
{
return (check(s1.substr(1,l1),s2) | check(s1, s2.substr(1,l2)));
}
else if(t==63)
{
return (check(s1,s2.substr(1,l2)) | check(s1.substr(1,l1), s2.substr(1,l2)));
}
return false;
}
int main()
{
//* = 42, ?=63
while(1)
{
string s1,s2;
cout<<"Enter first string(Base): ";
cin>>s1;
cout<<"Enter second string(Pattern): ";
cin>>s2;
int t=check(s1,s2);
if(t==1)
{
cout<<"\nOutput: True\n\n";
}
else
{
cout<<"\nOutput: False\n\n";
}
}
return 0;
}
1, check one by one
- m250892 October 30, 2018