diff options
| author | Jérémy Zurcher <jeremy@asynk.ch> | 2016-11-14 07:00:58 +0100 | 
|---|---|---|
| committer | Jérémy Zurcher <jeremy@asynk.ch> | 2016-11-14 07:00:58 +0100 | 
| commit | 7471f538c2203f266cb8002fb001183a9720a969 (patch) | |
| tree | 1ae9d4b366aa806391f2d40e2f458c5a7aa0f09e /04-algorithms_on_strings/04-suffix_array/01-kmp/kmp.cpp | |
| parent | eb0a213d040fb3b116ec030a6755216ce5e61ee9 (diff) | |
| download | coursera-7471f538c2203f266cb8002fb001183a9720a969.zip coursera-7471f538c2203f266cb8002fb001183a9720a969.tar.gz | |
Algorithms : add 04-algorithms_on_strings 04-suffix_array
Diffstat (limited to '04-algorithms_on_strings/04-suffix_array/01-kmp/kmp.cpp')
| -rw-r--r-- | 04-algorithms_on_strings/04-suffix_array/01-kmp/kmp.cpp | 29 | 
1 files changed, 29 insertions, 0 deletions
| diff --git a/04-algorithms_on_strings/04-suffix_array/01-kmp/kmp.cpp b/04-algorithms_on_strings/04-suffix_array/01-kmp/kmp.cpp new file mode 100644 index 0000000..13121ae --- /dev/null +++ b/04-algorithms_on_strings/04-suffix_array/01-kmp/kmp.cpp @@ -0,0 +1,29 @@ +#include <cstdio> +#include <iostream> +#include <string> +#include <vector> + +using std::cin; +using std::string; +using std::vector; + +// 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. +vector<int> find_pattern(const string& pattern, const string& text) { +  vector<int> result; +  // Implement this function yourself +  return result; +} + +int main() { +  string pattern, text; +  cin >> pattern; +  cin >> text; +  vector<int> result = find_pattern(pattern, text); +  for (int i = 0; i < result.size(); ++i) { +    printf("%d ", result[i]); +  } +  printf("\n"); +  return 0; +} | 
