Advertisement
evcamels

lr-5

Jan 17th, 2021
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<sstream>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     stringstream stream;
  10.     string a;
  11.     cout << "Введите строку: " << endl;
  12.     getline(cin, a);
  13.     stream.str(a);
  14.     string s;
  15.     int q = 0;
  16.     string d;
  17.     while (stream >> s)
  18.     {
  19.         q++;
  20.         if ((s == "no") || (s == "a"))
  21.         {
  22.             d += ", ";
  23.         }
  24.  
  25.         d += s + ' ';
  26.     }
  27.     int k = 0, n = d.length();
  28.     string temp1, temp2;
  29.     for ( int i = 0; i < (d.length() - 1); i++)
  30.     {
  31.         if (d[i] != ',')
  32.         {
  33.             k++;
  34.             if (d[i] != ' ')
  35.                 temp1 += d[i];
  36.         }
  37.  
  38.         else
  39.         {
  40.             if (k < n)
  41.             {
  42.                 n = k;
  43.                 temp2 = temp1;
  44.             }
  45.             k = 0;
  46.             temp1 = "";
  47.  
  48.         }
  49.     }
  50.     if (k < n)
  51.     {
  52.         temp2 = temp1;
  53.         n = k;
  54.     }
  55.  
  56.     cout << endl << d << endl << n << endl << temp2 << endl;
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement