Huawei trial-the most frequently-used element in the integer array, Huawei integer
Retrieve the elements that appear most frequently in an integer array and return them in ascending order.
Implementation Method:
Public static int [] calcTimes (int [] num, int len );
[Input] num: an integer array;
Len: Number of Integers
[Return] returns the most frequently-occurring elements in an integer array in ascending order.
[Note] You only need to complete the function algorithm, and there is no IO input or output in the middle.
Example
Input: num = {, 3, 4, 4, 9, 9, 10} len = 10
Return Value: {4, 9}
# Include <iostream> using namespace std; int compare (const void * p, const void * q) {return * (int *) p-* (int *) q ;} // The number size cannot exceed 10 void calcTimes (int num [], int len) {qsort (num, len, sizeof (int), compare ); int count [11] = {0}; for (int I = 0; I <len; I ++) count [num [I] ++; int max = count [0]; for (I = 0; I <11; I ++) if (count [I]> max) max = count [I]; for (I = 0; I <11; I ++) if (count [I] = max) cout <I <""; cout <endl ;} int main () {int n, I = 0, a [100]; cin> n ; While (getchar ()! = '\ N') {a [I ++] = n; cin> n ;}a [I ++] = n; calcTimes (a, I ); return 0 ;}
Test results may be incomplete. Check for missing information: