求出现次数超过一半的元素,采用moore's voting算法.
#include <stdio.h>
/*
Created by HarvestWu on 2018/4/25.
*/
int main()
{
int m ,n;
scanf("%d %d", &m, &n);
int count = 0, t = -1, a;
for (int i = 0; i < m*n; i++){
scanf("%d", &a);
if (count == 0){ t = a; count++; }
else{
if (t == a) count++;
else count--;
}
}
printf("%d", t);
return 0;
}