Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<unordered_map>
- #include <string>
- #include <map>
- int main()
- {
- std::map<std::string, int> sub_words;
- int line_len, word_len;
- std::cin >> line_len >> word_len;
- std::cin.ignore();
- std::string line;
- std::getline(std::cin, line);
- for(int i=0;i<=line_len - word_len ;i++)
- {
- std::string key = line.substr(i, word_len);
- if(sub_words.find(key) == sub_words.end())
- {
- //not found
- sub_words[key] = 1;
- }
- else
- {
- sub_words[key]++;
- }
- }
- //TODO take only keys with value of word_len
- //TODO find value from behin of list
- int max_number = 0;
- std::string max_key;
- std::map<std::string, int>::reverse_iterator it = sub_words.rbegin();
- max_key = it->first;
- max_number = it->second;
- for(;it != sub_words.rend();++it)
- {
- if(it->second > max_number)
- {
- max_number = it->second;
- max_key = it->first;
- }
- }
- std::cout << max_key<< std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement