2013统考真题
int Majority(int A[],int n)
{
int i,c,count=1;
m=A[0];
for(i=1;i<n;i++)
{
if(A[i]==m)
count++;
else
{
if(count>0)
count--;
else
{
m=A[i];
count=1;
}
}
}
if(count>0)
for(i=0,count=0;i<n;i++)
if(A[i]==m)
count++;
if(count>n/2)
return c;
else
return -1;
}