PhotoShaman

Untitled

Dec 29th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <windows.h>
  4.  
  5. using namespace std;
  6.  
  7. void main()
  8. {
  9.     SetConsoleCP(1251);
  10.     SetConsoleOutputCP(1251);
  11.     string txt, sl, slmin; // shnax — наибольшее слово
  12.     int k = 0, min = 0;
  13.     bool start = true;
  14.     cout << "Введите текст:\n";
  15.     getline(cin, txt);
  16.  
  17.     for (int i = 0; i < (int)txt.size(); i++)
  18.     {
  19.         if ((txt[i] == ' ') || (txt[i] == ',') || (txt[i] == '.'))
  20.         {
  21.             if (start)
  22.             {
  23.                 k = 1;
  24.                 min = sl.size();
  25.                 slmin = sl;
  26.                 start = false;
  27.             }
  28.             if ((int)sl.size() < min)
  29.             {
  30.                 if (!start) k = 1;
  31.                 min = sl.size();
  32.                 slmin = sl;
  33.             }
  34.             else if ((int)sl.size() == min)
  35.             {
  36.                 k++;
  37.             }
  38.             sl = ""; //освобождение sl для формирования слова
  39.         }
  40.         else
  41.         {
  42.             sl = sl + txt[i];
  43.         } //переменная s1 — формирует слово
  44.     }
  45.     cout << "\nslmin — " << slmin << " = " << k << " povtorin\n";
  46.     cin.get(); cin.get();
  47. }
Advertisement
Add Comment
Please, Sign In to add comment