Guest User

Untitled

a guest
Dec 17th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include<iostream>
  2. #include <string>
  3. #include<map>
  4. using namespace std;
  5. int main() {
  6.     std::map<std::string, int>m;
  7.     int sizeOfText;
  8.     int sizeOfWord;
  9.     std::string text;
  10.     std::cin >> sizeOfText >> sizeOfWord;
  11.     std::cin >> text;
  12.     std::string curr="";
  13.     for (size_t i = 0; i <= sizeOfText- sizeOfWord; i++) {
  14.         curr = text.substr(i,sizeOfWord);
  15.         m[curr]++;
  16.     }
  17.     int max = 0;
  18.     string maxS;
  19.     for (auto el : m) {
  20.         if (el.second > max) {
  21.             max = el.second;
  22.             maxS = el.first;
  23.         }
  24.     }
  25.     cout << maxS;
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment