Advertisement
VictoriaLodochkina

lab 4 z1-2 ALLLLLLLLL

Mar 20th, 2020
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.80 KB | None | 0 0
  1. #include <iostream>
  2. #define _USE_MATH_DEFINES
  3. #include <math.h>
  4. #include <string>
  5. #include <sstream>
  6. using namespace std;
  7. int searching_of_repeats(string);
  8. void entering(int, string);
  9. int ff(int, string);
  10. int main()
  11. {
  12.    // using namespace std;
  13.     setlocale(LC_ALL, "Russian");
  14.     long n;
  15.     char ex = 'n';
  16.     do {
  17.         cout << "Введите номер задания: " << endl;
  18.         char task;
  19.         //cin.ignore(100, '\n');
  20.         cin >> task;
  21.         cin.ignore(100, '\n');
  22.         cin.clear();
  23.         switch (task)
  24.         {
  25.         case '1': {
  26.             /*26.Дан текст, слова в котором разделены одинарным символом пробела, и
  27.             какая - то буква.Вывести все слова, в которых встречается эта буква.*/
  28.             string text, word;
  29.             string symbol;
  30.             cout << "Enter symbol: " << endl;
  31.             getline(cin, symbol);
  32.             symbol.resize(1);//чтобы было больше функций
  33.             cout << "Enter text: " << endl;
  34.             getline(cin, text);
  35.             stringstream words(text);
  36.             while (words >> word)
  37.             {
  38.                 bool flag = 0;
  39.                 for (int i = 0; i < word.length(); i++)//еще больше функций!!!!!!!!!
  40.                 {
  41.                     if (word.find(symbol) != string::npos)
  42.                     {
  43.                         flag = 1;;
  44.                     }
  45.                 }
  46.                 if (flag)
  47.                 {
  48.                     cout << word << endl;
  49.                 }
  50.             }
  51.             break;
  52.         }
  53.         case '2': {
  54.             /*Дан текст на английском языке, слова в котором разделены одинарным
  55.             символом пробела. Определить слово (слова) с максимальным числом
  56.             повторяющихся букв*/
  57.             cout << "Enter text: " << endl;
  58.             string text, rez;
  59.             getline(cin, text);
  60.             int maxs = searching_of_repeats(text);
  61.             entering(maxs, text);
  62.             break;
  63.         }
  64.         default: {cout << "Нет такой задачи.\n"; } break;
  65.         }
  66.         cout << "Если вы хотите выйти, нажмите \'y\', в противном случае-любую другую клавишу" << endl;
  67.        // cin.ignore(100, '\n');
  68.         cin >> ex;
  69.     } while (ex != 'y');
  70.     return 0;
  71. }
  72. int searching_of_repeats(string str)
  73. {
  74.     string word;
  75.     int maxrep = 0;
  76.     stringstream ss(str);
  77.     while (ss >> word)
  78.     {
  79.         int maxs1 = ff(maxrep, word);
  80.         if (maxs1 > maxrep)
  81.         {
  82.             maxrep = maxs1;
  83.         }
  84.     }
  85.     return maxrep;
  86.     ss.str("");
  87. }
  88.  
  89. void entering(int maxrep, string text1)
  90. {
  91.     string rez;
  92.     string word;
  93.     stringstream s(text1);
  94.     while (s >> word)
  95.     {
  96.         int maxs1 = ff(maxrep, word);
  97.         if (maxs1 > maxrep)
  98.         {
  99.             maxrep = maxs1;
  100.         }
  101.         if (maxs1 == maxrep)
  102.         {
  103.             rez += word;
  104.             rez += " ";
  105.         }
  106.     }
  107.     cout << rez;
  108.     s.str("");
  109. }
  110.  
  111. int ff(int maxrep1, string word1)
  112. {
  113.     int maxs1 = 0;
  114.     int* mas = new int[word1.length()];
  115.     for (int l = 0; l < word1.length(); l++)
  116.     {
  117.         mas[l] = 0;
  118.     }
  119.     for (int t = 0; t < word1.length(); t++)
  120.     {
  121.         if (word1.find(word1[t]) <= t)
  122.         {
  123.             mas[word1.find_first_of(word1[t])]++;
  124.         }
  125.     }
  126.     for (int l = 0; l < word1.length(); l++)
  127.     {
  128.         if (mas[l] > maxs1)
  129.         {
  130.             maxs1 = mas[l];
  131.         }
  132.     }
  133.     delete[] mas;
  134.     return maxs1;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement