Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include <string>
- #include<map>
- using namespace std;
- int main() {
- std::map<std::string, int>m;
- int sizeOfText;
- int sizeOfWord;
- std::string text;
- std::cin >> sizeOfText >> sizeOfWord;
- std::cin >> text;
- std::string curr="";
- for (size_t i = 0; i <= sizeOfText- sizeOfWord; i++) {
- curr = text.substr(i,sizeOfWord);
- m[curr]++;
- }
- int max = 0;
- string maxS;
- for (auto el : m) {
- if (el.second > max) {
- max = el.second;
- maxS = el.first;
- }
- }
- cout << maxS;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment