Search
 
SCRIPT & CODE EXAMPLE
 

CPP

naive pattern matching algorithm

#include <bits/stdc++.h> 
using namespace std; 
  
void search(char* pat, char* txt) 
{ 
    int M = strlen(pat); 
    int N = strlen(txt); 
  
    /* A loop to slide pat[] one by one */
    for (int i = 0; i <= N - M; i++) { 
        int j; 
  
        /* For current index i, check for pattern match */
        for (j = 0; j < M; j++) 
            if (txt[i + j] != pat[j]) 
                break; 
  
        if (j == M) // if pat[0...M-1] = txt[i, i+1, ...i+M-1] 
            cout << "Pattern found at index "
                 << i << endl; 
    } 
} 
Comment

PREVIOUS NEXT
Code Example
Cpp :: how to delete a file in cpp 
Cpp :: declare nullptr c++ 
Cpp :: how to find the sum of a vector c++ 
Cpp :: how to dynamically allocate an array c++ 
Cpp :: c++ vector initialization 
Cpp :: c++ how to add something at the start of a vector 
Cpp :: for c++ 
Cpp :: back() in c++ 
Cpp :: hello world in c++ 
Cpp :: find prime number c++ 
Cpp :: c++ string to int 
Cpp :: how to find last character of string in c++ 
Cpp :: comparator in sort c++ 
Cpp :: how do you wait in C++ 
Cpp :: Header for INT_MIN 
Cpp :: json::iterator c++ 
Cpp :: unordered_set to vector 
Cpp :: c++ cout without include iostream 
Cpp :: priority queue in c++ 
Cpp :: pure virtual function in c++ 
Cpp :: what is meant by pragma once in c++ 
Cpp :: How do I read computer current time in c++ 
Cpp :: c++ convert const char* to int 
Cpp :: Function to calculate compound interest in C++ 
Cpp :: structure of a function in C++ 
Cpp :: c ++ split_string 
Cpp :: data types in c++ 
Cpp :: Bucket and Water Flow codechef solution in c++ 
Cpp :: C++ wchar_t 
Cpp :: c++ variable type 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =