Task : Find the pattern from the text. If the pattern is present print found else print not found.
Example:
Input:
2
hellofriends
hello
asdfghjkl
ask
Output:
found
not found
Here is the Code :
Program in C++:
- #include<iostream>
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int t;
- cin>>t;
- while(t--)
- {
- string s1,s2;
- cin>>s1;
- cin>>s2;
- int n=s1.length(),m=s2.length();
- // Implementation of logic
- if(n<m)
- {
- cout<<"not found"<<endl;
- }
- else
- {
- int c = 0;
- for(int i=0;i<=n-m;i++)
- {
- string t = s1.substr(i,m);
- if(t == s2)
- {
- cout<<"found"<<endl;
- c=1;
- break;
- }
- }
- if(c==0) cout<<"not found"<<endl;
- }
- }
- return 0;
- }
Here is the Video: