c++ program to perform naive string matching

admin May 25, 2013 0 Comments

WRITE A PROGRAM TO PERFORM NAÏVE STRING MATCHING

#include<iostream.h>
#include<conio.h>
#include<string.h>

void main()
{
clrscr();
intn,m,s;
char t[50], p[50];
cout<<"Enter text"<<endl;
cin>>t;
cout<<"Enter pattern"<<endl;
cin>>p;
m=strlen(p);
n=strlen(t);
for(s=0;s<=(n-m);s++)
{
for(int i=0;i<=m;i++)
{
if(t[s+i]!=p[i])
break;
}
if(i=m)
cout<<"Valid Shift"<<endl;
cout<<"shift is"<<s;
}
getch();
}

OUTPUT :

 

C++ programs for the implementation of Breadth First Search ...

Output-for-activity-breadth -first-search

Leave a Reply