VictoriaLodochkina

lab 4 z2 streams

Mar 20th, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. using namespace std;
  5. int searching_of_repeats(string);
  6. void entering(int, string);
  7. int main()
  8. {
  9.     cout << "Enter text: " << endl;
  10.     string text, rez;
  11.     getline(cin, text);
  12.     int maxs = searching_of_repeats(text);
  13.     entering(maxs, text);
  14.     return 0;
  15. }
  16.  
  17. int searching_of_repeats(string str)
  18. {
  19.     string word;
  20.     int maxrep = 0;
  21.     stringstream ss(str);
  22.     while (ss >> word)
  23.     {
  24.         int maxs1 = 0;
  25.         int* mas = new int[word.length()];
  26.         for (int l = 0; l < word.length(); l++)
  27.         {
  28.             mas[l] = 0;
  29.         }
  30.         for (int t = 0; t < word.length(); t++)
  31.         {
  32.             if (word.find(word[t]) <= t)
  33.             {
  34.                 mas[word.find_first_of(word[t])]++;
  35.             }
  36.         }
  37.         for (int l = 0; l < word.length(); l++)
  38.         {
  39.             if (mas[l] > maxs1)
  40.             {
  41.                 maxs1 = mas[l];
  42.             }
  43.         }
  44.         if (maxs1 > maxrep)
  45.         {
  46.             maxrep = maxs1;
  47.         }
  48.         delete[] mas;
  49.     }
  50.     return maxrep;
  51.     ss.str("");
  52. }
  53.  
  54. void entering(int maxrep, string text1)
  55. {
  56.     string rez;
  57.     string word;
  58.     stringstream s(text1);
  59.     while (s >> word)
  60.     {
  61.         int maxs1 = 0;
  62.         int* mas = new int[word.length()];
  63.         for (int l = 0; l < word.length(); l++)
  64.         {
  65.             mas[l] = 0;
  66.         }
  67.         for (int t = 0; t < word.length(); t++)
  68.         {
  69.             if (word.find(word[t]) <= t)
  70.             {
  71.                 mas[word.find_first_of(word[t])]++;
  72.             }
  73.         }
  74.         for (int l = 0; l < word.length(); l++)
  75.         {
  76.             if (mas[l] > maxs1)
  77.             {
  78.                 maxs1 = mas[l];
  79.             }
  80.         }
  81.         if (maxs1 > maxrep)
  82.         {
  83.             maxrep = maxs1;
  84.         }
  85.         if (maxs1 == maxrep)
  86.         {
  87.             rez += word;
  88.             rez += " ";
  89.         }
  90.         delete[] mas;
  91.     }
  92.     cout << rez;
  93.     s.str("");
  94. }
Add Comment
Please, Sign In to add comment