palenda21

экз4

Jan 8th, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.95 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     char str[50];
  6.     cin.getline(str, 50);
  7.     int n = strlen(str);
  8.     bool p = false;
  9.     for (int i = 0; i < n; i++)
  10.     {
  11.         if ((i == 0) || (str[i] != ' ' && str[i - 1] == ' '))
  12.         {
  13.             p = false;
  14.             for (int j = i; str[j] != ' '; j++)
  15.             {
  16.                 if (str[j] == 'w')
  17.                 {
  18.                     p = true;
  19.                     break;
  20.                 }
  21.             }
  22.  
  23.             if (p == true)
  24.             {
  25.                 for (int j = i; str[j] != ' '; j++)
  26.                 {
  27.                     cout << str[j];
  28.                     if (j == n - 1)
  29.                     {
  30.                         break;
  31.                     }
  32.                 }
  33.                 cout << endl;
  34.             }
  35.         }
  36.     }
  37.     int count = 3;
  38.  
  39.     cout << endl;
  40.     bool f = false;
  41.    
  42.     if (str[n - count-1] == ' ')
  43.     {
  44.         for (int j = n - 1; j != n - count; j--)
  45.         {
  46.             if (str[j] == ' ')
  47.             {
  48.                 f = true;
  49.             }
  50.  
  51.         }
  52.  
  53.     }
  54.     else
  55.     {
  56.         f = true;
  57.         cout << "last slovo ne iz 3 bukv";
  58.     }
  59.     int count1 = 0;
  60.     bool g = false;
  61.  
  62.     cout << endl;
  63.  
  64.     if (f == false)
  65.     {
  66.         for (int i = n - 1; i >= (n - count); i--)
  67.         {
  68.             cout << str[i];
  69.         }
  70.     }
  71.     else if (f == true)
  72.     {
  73.         for (int i = 0; i < n; i++)
  74.         {
  75.             if (str[i] != ' ' && str[i - 1] == ' ')
  76.             {
  77.                 count1++;
  78.             }
  79.             if (count1 == 3)
  80.             {
  81.                 g = true;
  82.                 for (int j = i; str[j] != ' '; j++)
  83.                 {
  84.                     cout << str[j];
  85.                     if (j == n - 1)
  86.                     {
  87.                         break;
  88.                     }
  89.  
  90.                 }
  91.                 break;
  92.             }
  93.         }
  94.     }
  95.    
  96. }
Add Comment
Please, Sign In to add comment