Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <string>
- #include <vector>
- using namespace std;
- template <typename Term>
- map<Term, int> ComputeTermFreqs(const vector<Term>& terms) {
- map<Term, int> term_freqs;
- for (const Term& term : terms) {
- ++term_freqs[term];
- }
- return term_freqs;
- }
- pair<string, int> FindMaxFreqAnimal(const vector<pair<string, int>>& animals) {
- int max_value = 0;
- pair<string, int>ret_pair;
- for(const auto& [term, value]: ComputeTermFreqs(animals)){
- if(max_value < value){
- max_value = value;
- ret_pair = term;
- }
- }
- return ret_pair;
- }
- int main() {
- const vector<pair<string, int>> animals = {
- {"Murka"s, 5}, // 5-летняя Мурка
- {"Belka"s, 6}, // 6-летняя Белка
- {"Murka"s, 7}, // 7-летняя Мурка не та же, что 5-летняя!
- {"Murka"s, 5}, // Снова 5-летняя Мурка
- {"Belka"s, 6}, // Снова 6-летняя Белка
- };
- const pair<string, int> max_freq_animal = FindMaxFreqAnimal(animals);
- cout << max_freq_animal.first << " "s << max_freq_animal.second << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement