Advertisement
totobac

Untitled

Jan 11th, 2021
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. // Напишете рекурсивна функция, която приема два символни низа и проверява дали всички символи от първия низ се съдържат във втория.
  2.  
  3. #include <iostream>
  4. #include <cstring>
  5. using namespace std;
  6. const int MAX_SIZE = 100;
  7.  
  8. bool isTrue (char firstStr[],char secondStr[], bool &flag, int i, int &secondSize)
  9. {
  10.     int counter = 0;
  11.     bool isSame = false;
  12.     while (counter <= secondSize)
  13.     {
  14.         if (isSame == false)
  15.         {
  16.  
  17.             if (firstStr[i] == secondStr[counter])
  18.                 isSame = true;
  19.             counter++;
  20.         }
  21.         else break;
  22.  
  23.     }
  24.     flag = isSame;
  25.  
  26.     if (i == strlen(firstStr) || flag == false)
  27.        return flag;
  28.  
  29.     isTrue(firstStr, secondStr, flag, i + 1, secondSize);
  30.    
  31. }
  32.  
  33.  
  34.  
  35.  
  36. int main()
  37. {
  38.     bool flag = true;
  39.     char firstStr[MAX_SIZE];
  40.     char secondStr[MAX_SIZE];
  41.     cout << "Enter the first string: " << endl;
  42.     cin >> firstStr;
  43.     cout << "Enter the second string: " << endl;
  44.     cin >> secondStr;
  45.     int secondSize = strlen(secondStr);
  46.  
  47.     if (isTrue(firstStr, secondStr, flag, 0, secondSize))
  48.         cout << "YES";
  49.     else
  50.         cout << "NO";
  51.     return 0;
  52. }
  53.  
  54.  
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement