Skip to content

Instantly share code, notes, and snippets.

@Phitherek
Created October 4, 2012 19:53
Show Gist options
  • Save Phitherek/3835989 to your computer and use it in GitHub Desktop.
Save Phitherek/3835989 to your computer and use it in GitHub Desktop.
algoprep p. 2
Use algoprep.cpp, algoprep.h and Makefile from here: https://gist.github.com/3721876
#include <iostream>
#include <cstdlib>
#include "algoprep.h"
using namespace std;
void nstringmatcher(string T, string P) {
int n = T.length();
int m = P.length();
for(int s = 0; s < n-m; s++) {
if(P == T.substr(s, m)) {
cout << "Found a match with offset: " << s << endl;
}
}
return;
}
int main() {
string T, P;
cout << "Enter text: " << endl;
cin >> T;
cout << "Enter text to match: " << endl;
cin >> P;
nstringmatcher(T, P);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment