Advertisement
VictoriaLodochkina

lab 4 z 2 MORE FUNCT

Mar 20th, 2020
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.56 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 ff(int, string);
  8. int main()
  9. {
  10.     cout << "Enter text: " << endl;
  11.     string text, rez;
  12.     getline(cin, text);
  13.     int maxs = searching_of_repeats(text);
  14.     entering(maxs, text);
  15.     return 0;
  16. }
  17.  
  18. int searching_of_repeats(string str)
  19. {
  20.     string word;
  21.     int maxrep = 0;
  22.     stringstream ss(str);
  23.     while (ss >> word)
  24.     {
  25.         int maxs1 = ff(maxrep, word);
  26.         if (maxs1 > maxrep)
  27.         {
  28.             maxrep = maxs1;
  29.         }
  30.     }
  31.     return maxrep;
  32.     ss.str("");
  33. }
  34.  
  35. void entering(int maxrep, string text1)
  36. {
  37.     string rez;
  38.     string word;
  39.     stringstream s(text1);
  40.     while (s >> word)
  41.     {
  42.         int maxs1=ff(maxrep, word);
  43.       if (maxs1 > maxrep)
  44.         {
  45.             maxrep = maxs1;
  46.         }
  47.         if (maxs1 == maxrep)
  48.         {
  49.             rez += word;
  50.             rez += " ";
  51.         }
  52.     }
  53.     cout << rez;
  54.     s.str("");
  55. }
  56.  
  57. int ff(int maxrep1, string word1)
  58. {
  59.     int maxs1 = 0;
  60.     int* mas = new int[word1.length()];
  61.     for (int l = 0; l < word1.length(); l++)
  62.     {
  63.         mas[l] = 0;
  64.     }
  65.     for (int t = 0; t < word1.length(); t++)
  66.     {
  67.         if (word1.find(word1[t]) <= t)
  68.         {
  69.             mas[word1.find_first_of(word1[t])]++;
  70.         }
  71.     }
  72.     for (int l = 0; l < word1.length(); l++)
  73.     {
  74.         if (mas[l] > maxs1)
  75.         {
  76.             maxs1 = mas[l];
  77.         }
  78.     }
  79.     delete[] mas;
  80.     return maxs1;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement