多元素定义:多元素即在数列中出现次数多于n/2的元素,即超过50%
性质:在一个序列中如果去掉2个不同的元素,那么原序列中的多元素,在新的序列中还是多元素,
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a[] = {3,1,1,2,3,1,3,3,3};
int i;
//初始化
int count = 1;
int temp = a[0];
for(i = 1; i < sizeof(a)/sizeof(int);i++)
{
if(count == 0)
{
temp = a[i];
count++;
}
else if(a[i] == temp)
count++;
else
count--;
}
printf("最多的数是:%d\n",temp);
system("pause");
return 0;
}