Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Напишете рекурсивна функция, която приема два символни низа и проверява дали всички символи от първия низ се съдържат във втория.
- #include <iostream>
- #include <cstring>
- using namespace std;
- const int MAX_SIZE = 100;
- bool isTrue (char firstStr[],char secondStr[], bool &flag, int i, int &secondSize)
- {
- int counter = 0;
- bool isSame = false;
- while (counter <= secondSize)
- {
- if (isSame == false)
- {
- if (firstStr[i] == secondStr[counter])
- isSame = true;
- counter++;
- }
- else break;
- }
- flag = isSame;
- if (i == strlen(firstStr) || flag == false)
- return flag;
- isTrue(firstStr, secondStr, flag, i + 1, secondSize);
- }
- int main()
- {
- bool flag = true;
- char firstStr[MAX_SIZE];
- char secondStr[MAX_SIZE];
- cout << "Enter the first string: " << endl;
- cin >> firstStr;
- cout << "Enter the second string: " << endl;
- cin >> secondStr;
- int secondSize = strlen(secondStr);
- if (isTrue(firstStr, secondStr, flag, 0, secondSize))
- cout << "YES";
- else
- cout << "NO";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement