Website Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit3f8ae19df71d90a1a72a9ff9f4c5c79da693e7d2 (patch)
Author
 Angel Dimitriev <achi_d@abv.bg>
2022-01-05 18:20:58 +0200
Committer
 GitHub <noreply@github.com>
2022-01-05 18:20:58 +0200
Files16816a6dc8f290b6aae68447dff72fe9d5f1b32c
Introduction_to_programming_FMI-3f8ae19df71d90a1a72a9ff9f4c5c79da693e7d2.tar
Introduction_to_programming_FMI-3f8ae19df71d90a1a72a9ff9f4c5c79da693e7d2.tar.gz
Introduction_to_programming_FMI-3f8ae19df71d90a1a72a9ff9f4c5c79da693e7d2.zip
Parent30eb3cf6792a937909ea0583a0383806309e587f (diff)
Create searchInText.cpp
1 files changed, 27 insertions, 0 deletions
-rw-r--r--Sem. 12/searchInText.cpp27
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);
+}
+
+