GeeksforGeeks Solution For Hard Domain .Below You Can Find The Solution Of School Basic ,Easy ,Medium . Or Hackerrank Solution You Can Also Direct Submit Your Solution to Geeksforgeeks Same Problem .You Need to login then you can submit you answers
Problem :- Pattern Searching
Submit Your Solution :- Click Here
Solution :-
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int l,i,j,l1,tmp=0,cnt=0;
string str,s;
cin>>str;
cin>>s;
l=str.length();
l1=s.length();
for(i=0;i<=l-l1;i++)
{
for (j=0;j<l1;j++)
{
if (str[i+j]!=s[j])
break;
}
if (j==l1)
cnt=1;
}
if(cnt==1)
cout<<"found\n";
else
cout<<"not found\n";
}
return 0;
}
Output:-
0 Comments: