Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int max_occurrences(int [], size_t);
- int digitOccurence(long int number, int digit);
- int main() {
- int array[] = { 1, 2, 3, 4, 5, 6, 6 };
- cout << endl << max_occurrences(array, 7) << endl;
- return 0;
- }
- int max_occurrences(int array[], size_t array_size) {
- string str;
- string::size_type sz;
- size_t max_count = 1, result = 0;
- for (size_t i = 0; i < array_size; i++) {
- str += to_string(array[i]);
- }
- long number = stol(str, &sz);
- cout << number << endl;
- for (size_t i = 0; i < 10; i++) {
- int count = digitOccurence(number, i);
- if (count >= max_count) {
- max_count = count;
- result = i;
- }
- }
- return result;
- }
- int digitOccurence(long int number, int digit) {
- int count = 0;
- while (number) {
- if (number % 10 == digit)
- count++;
- number /= 10;
- }
- return count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement