Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
substring search
//Title of this code #include <iostream> #include <string> using namespace std; bool substringSearchHelper(const string& str, const string& pattern, int sPos, int pPos, int error) { if (sPos >= str.length() || pPos >= pattern.length() || error < 0) return false; if (pPos == pattern.length() - 1 && error >= 0) return true; if (str[sPos] != pattern[pPos]) return ( substringSearchHelper(str, pattern, sPos + 1, pPos + 1, error - 1) || substringSearchHelper(str, pattern, sPos, pPos + 1, error - 1) || substringSearchHelper(str, pattern, sPos + 1, pPos, error - 1) ); return substringSearchHelper(str, pattern, sPos + 1, pPos + 1, error); } bool substringSearch(const string& str, const string& pattern, int error) { bool ret = false; for (int i = 0; i < str.length(); ++i) { if (substringSearchHelper(str, pattern, i, 0, error)) { cout << "Match at position: " << i << "." << endl; ret = true; } } return ret; } int main() { cout << boolalpha << substringSearch("hellobello", "llo", 1); }
run
|
edit
|
history
|
help
0
sysFork3
Pac update
Simulare 2022
vem de livezada
Arithemetic operators
StackTel
expm1
Avoiding visited networked paths
Anagrams WIP
offsetof