blob: 333b8b16593d170d001710c0c8bbc9bd30f3648f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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);
}
|