From 3f8ae19df71d90a1a72a9ff9f4c5c79da693e7d2 Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Wed, 5 Jan 2022 18:20:58 +0200 Subject: Create searchInText.cpp --- Sem. 12/searchInText.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Sem. 12/searchInText.cpp (limited to 'Sem. 12/searchInText.cpp') 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 + +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); +} + + -- cgit v1.3.1-23-gd82d