首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 其他相关 >

众数有关问题

2012-10-25 
众数问题#include stdio.h#include stringusing namespace std int main(){int min,max int nint i

众数问题

#include <stdio.h>
#include <string>
using namespace std ;

int main()
{
int min,max ;
int n;
int inta[100000] ;
int i;

while(scanf("%d",&n)!=EOF)
{
   min=1000000000;
   max=0;

   memset(inta,0,sizeof(inta) ) ;
   int a;
   for(i=0;i<n;i++)
   {
    scanf("%d",&a) ;
    inta[a] ++ ;
    if(a>max)
     max=a ;
    if(min>a)
     min=a;
   }
   int Index=min,num=inta[min] ;
   for(i=min+1;i<=max;i++)
   {
    if(inta[i]>num)
    {
     num=inta[i] ;
     Index=i ;
    }
   }
   printf("%d\n%d\n",Index,num ) ;
}
return 0;
}

热点排行