diff options
1 files changed, 27 insertions, 0 deletions
| -rw-r--r-- | Sem. 12/searchInText.cpp | 27 |
diff --git a/Sem. 12/searchInText.cpp b/Sem. 12/searchInText.cpp new file mode 100644 index 0000000..333b8b1 --- /dev/null +++ b/Sem. 12/searchInText.cpp @@ -0,0 +1,27 @@ +#include <iostream> + +bool isPrefix(const char* text, const char* pattern) +{ + if (*pattern == '\0') + return true; + return *text == *pattern && isPrefix(text + 1, pattern + 1); +} + +bool searchInText(const char* text, const char* pattern) +{ + if (*text == '\0') + return *pattern == '\0'; + + return isPrefix(text, pattern) || searchInText(text + 1, pattern); +} + + +int main() +{ + char str[] = "hello friends how are you"; + char pattern[] = "friends!"; + + std::cout << searchInText(str, pattern); +} + + |
