I came up with this algorithm for matching exact strings after I tried understanding the ones already on the internet and terribly failing :P Can anyone please tell me if this is fast or slow as compared to pre-existing algorithms?

```
#include <iostream>
#include<cstring>

using namespace std;

int main(){

int i=0;
int j=0;
int foo=0;

string str;
string needle;

cin>>str;
cin>>needle;

int * arr = NULL;
int * arr2 = NULL;
int * match = NULL;

arr = new int [str.length()];

int x=0, y = 0, z = 0;
int n=0; char a, b;

cout<<"\nStep 1: ";

for(i=0;i<str.length();i++){
    if(str[i]==needle[0]){
        arr[x]=i; x++;
        cout<<i<<" ";
    }
}

arr[x]=str.length(); x++; cout<<"\nStep 2: ";

if(x){
    arr2 = new int [x];

    for(i=0;i<x-1;i++){
        if(arr[i+1]-arr[i]>=needle.length()){
            arr2[y]=arr[i]; y++;
            cout<<arr[i]<<" ";
        }
    }

    delete[]arr; cout<<"\nStep 3: ";

    if(y){
        match = new int [y];
        for(i=0;i<y;i++){
            n=arr2[i];
            for(j=0;j<needle.length(); j++){
                a=str[n+j]; b=needle[j];
                if(a==b){
                    foo=1;
                }
                else{
                    foo=0; break;
                }
            }
            if(foo){
                match[z]=n; z++;
                cout<<n<<" ";
            }
        }

        delete[]arr2;

        if(z){

        cout<<"\n\nMatches: ";
          for(i=0;i<z;i++){
            cout<<match[i]<<" ";
          }
        }
    }
  } 
return 0;
}

```