I have a list which contains numeric strings. The numeric strings in list may start with any number from 1 to 9 (it doesn't start with "0"). Now i need to find three top occurrences in the list.
Ex: 1234 2345 2343 4356 6434 2343 2222 4545 6666 6653
top开发者_运维技巧 three occurrences in the above list respectively are 2,6,4.
int occurences[10]; // Store numbers occurences in number index
For example if occurence of 5 is equal to 6 then occurences[5] = 6
Second thing you must do is write a function to get count of occurences.
int occurence(int number)
{
int i=0;
for(;i<listSize;i++) {
if(atoi(myList[i]) == number)
occurences[number]++;
}
}
The last thing you must do is find the biggest 3 element in occurences array.
精彩评论