Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int biggest_sum(int *arr, int n)
- {
- // {1, 4, 2, 2, 3, 3, 2, 4, 2}
- // 0,0,0,0,0,0,0,0,0
- // 0,1,8,6,8,0,0,0,0
- // 0,1,2,3,4,5,6,7,8
- // n = 9
- int *count_array;
- count_array = (int*)calloc(n, sizeof(int));
- int max = 0;
- int max_index;
- for(int i = 0; i < n; i++)
- {
- // int count_arr_value = count_array[arr[i]];
- // int count_arr_index = arr[i];
- count_array[arr[i]] += arr[i];
- if(count_array[arr[i]] > max)
- {
- max = count_array[arr[i]];
- max_index = arr[i];
- }
- else if(count_array[arr[i]] == max)
- {
- if(max_index < arr[i])
- max_index = arr[i];
- }
- }
- return max_index;
- }
- void main()
- {
- int arr[9] = {1, 4, 2, 2, 3, 3, 2, 2, 7};
- int x = biggest_sum(arr, 9);
- printf("%d", x);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement