Created
October 19, 2014 11:49
-
-
Save magmel48/344149bd1b5c3ada0105 to your computer and use it in GitHub Desktop.
for alexander
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <map> | |
int main (void) { | |
int arr[] = {1, 2, 3, 4, 5, 4, 3, 2, 2, 1, 1, 2, 2, 2}; | |
std::vector<int> source (arr, arr + sizeof(arr) / sizeof(arr[0])); | |
std::map<int, int> result; | |
std::map<int, int>::iterator iter; | |
for (int i = 0; i != source.size(); ++i) { | |
if (result.count(source.at(i) == 0)) { | |
result.insert(std::pair<int, int>(source.at(i), 1)); | |
} else { | |
result[source.at(i)]++; | |
} | |
} | |
std::pair<int, int> maxOccurrence(result.begin()->first, result.begin()->second); | |
for (iter = result.begin(); iter != result.end(); ++iter) { | |
if (maxOccurrence.second < iter->second) { | |
maxOccurrence = std::pair<int, int>(iter->first, iter->second); | |
} | |
} | |
std::cout << "result: " << maxOccurrence.first; | |
fgetc(stdin); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment