Skip to content
This repository was archived by the owner on May 30, 2021. It is now read-only.

Added Naive Pattern Searching under String Algorithms in C++ #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions C++/naive_pattern_searching.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//naive pattern searching - abee62
#include<bits/stdc++.h>
using namespace std;
int main()
{
char s[1000],pat[1000],flag=0;
cout<<"Enter the complete text in which you want to search\n";
cin.getline(s,1000);
cout<<"Enter the pattern\n";
cin.getline(pat,1000);
int a,b;
a=strlen(s);
b=strlen(pat);
for(int i=0;i<=(a-b);i++ )
{
int j;
for(j=0;j<b;j++)
{
if(s[i+j]!=pat[j])
break;
}
if(j==b)
{cout<<"Pattern found at index "<<i<<endl;
flag=1;}

}
if(flag==0)
cout<<"Pattern not found";

return 0;

}