开发者

How to find the number of numeric starts with and find the top 3 count among them?

开发者 https://www.devze.com 2023-04-07 15:12 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消