Advertisement
Guest User

фыв

a guest
Dec 18th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int search(char* Word, char* Word2)
  5. {
  6.     int n = 0, g = 0, N = 0;
  7.     for (int i = 0; ; i++)
  8.     {
  9.         if (Word2[i] != '\0')
  10.         {
  11.             n++;
  12.         }
  13.         else break;
  14.     }
  15.  
  16.     for (int i = 0; ; i++)
  17.     {
  18.         if (Word[i] != '\0')
  19.         {
  20.             N++;
  21.         }
  22.         else break;
  23.     }
  24.  
  25.     for (int i = 0; i < N + 1; i++)
  26.     {
  27.         for (int j = 0; j < n; j++)
  28.         {
  29.             if (Word[i] == Word2[j])
  30.             {
  31.                 g++;
  32.                 Word[i] = '\0';
  33.             }
  34.         }
  35.     }
  36.  
  37.     if (g >= n)
  38.     {
  39.         for (int i = 0; i < n; i++)
  40.         {
  41.             Word[i] = Word2[i];
  42.             if (i == (n - 1))
  43.             {
  44.                 Word[n] = '\0';
  45.                 return 1;
  46.             }
  47.         }
  48.     }
  49.     else
  50.     {
  51.         return 0;
  52.     }
  53.  
  54.  
  55.  
  56. }
  57.  
  58. int main() {
  59.     setlocale(0, "");
  60.  
  61.     int N(15);
  62.  
  63.     char* Word = new char[N];
  64.  
  65.     cout << "Введите первое слово: ";
  66.  
  67.     cin.getline(Word, N);
  68.  
  69.  
  70.     char* Word2 = new char[N];
  71.  
  72.     cout << "Введите второе слово: ";
  73.  
  74.     cin.getline(Word2, N);
  75.  
  76.  
  77.     switch (search(Word, Word2))
  78.     {
  79.     case 1:
  80.         cout << Word << endl;
  81.         cout << "Слово найдено!" << endl;
  82.         break;
  83.     default:
  84.         cout << "Слово не найдено" << endl;
  85.         break;
  86.     }
  87.  
  88.     delete[] Word;
  89.     delete[] Word2;
  90.     system("pause");
  91.     return(0);
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement