kmp.cpp
static vector<int> find_pattern(const string &pattern, const string &text)
{
	vector<int> result;
	string s = pattern + "$" + text;
	vector<int> pref = compute_prefix_fun(s);

	for (size_t i = pattern.size() + 1; i < s.size(); i++) {
		if (pref[i] == pattern.size()) {
			result.push_back(i - 2*pattern.size());
		}
	}
	cout << endl;

	return result;
}
// Find all occurrences of the pattern in the text and return a
// vector with all positions in the text (starting from 0) where 
// the pattern starts in the text.
Find all occurrences of the pattern in the text and return a
vector with all positions in the text (starting from 0) where
the pattern starts in the text.
Find all occurrences of the pattern in the text and return a vector with all positions in the text ( starting from 0 ) where the pattern starts in the text .
static vector<int> find_pattern(const string &pattern, const string &text)
{
	vector<int> result;
	string s = pattern + "$" + text;
	vector<int> pref = compute_prefix_fun(s);
	for (size_t i = pattern.size() + 1; i < s.size(); i++) {
		if (pref[i] == pattern.size()) {
			result.push_back(i - 2*pattern.size());
		}
	}
	cout << endl;
	return result;
}
static vector < int > find_pattern ( const string & pattern , const string & text ) { vector < int > result ; string s = pattern + " " + text ; vector < int > pref = compute_prefix_fun ( s ) ; for ( size_t i = pattern . size ( ) + 1 ; i < s . size ( ) ; i ++ ) { if ( pref [ i ] == pattern . size ( ) ) { result . push_back ( i - 2 * pattern . size ( ) ) ; } } cout << endl ; return result ; }
Find all occurrences of the pattern in the text and return a
vector with all positions in the text (starting from 0) where
the pattern starts in the text.
Find all occurrences of the pattern in the text and return a vector with all positions in the text ( starting from 0 ) where the pattern starts in the text .