-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNaiveAlgo.cpp
More file actions
34 lines (31 loc) · 754 Bytes
/
Copy pathNaiveAlgo.cpp
File metadata and controls
34 lines (31 loc) · 754 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//author @Nishant
#include<bits/stdc++.h>
using namespace std;
void naiveSearch(char txt[], char pat[]){
int txtLen = strlen(txt);
int patLen = strlen(pat);
for(int i=0; i<=txtLen - patLen; i++){
int j = 0;
for(j=0; j<patLen; j++){
if(txt[i+j] != pat[j]){
break;
}
}
if(j==patLen){
cout << "Pattern found at index " << i << endl;
}
}
}
int main(){
char txtS[100], patS[100];
cin.getline(txtS, 100);
cin.getline(patS, 100);
string txt, pat;
// for(int i=0; i<strlen(txtS); i++){
// txt += txtS[i];
// }
// for(int i=0; i<strlen(patS); i++){
// pat += patS[i];
// }
naiveSearch(txtS, patS);
}