Tango 水王

贴代码

#include <stdio.h>
/***********************************************************************************
Tango是微软亚洲研究院的一个试验项目。研究院的员工和实习生们都很喜欢在Tango上面交流灌水。
传说,Tango有一大“水王”,他不但喜欢发贴,还会回复其他ID发的每个帖子。坊间风闻该“水王”
发帖数目超过了帖子总数的一半。如果你有一个当前论坛上所有帖子(包括回帖)的列表,其中帖
子作者的ID也在表中,你能快速找出这个传说中的Tango水王吗?

**********************************************************************************
*/
int findnx(int *array,const int n);
int main()
{
int array[]={1,1,2,6,1,4,1,2,1};
int result = findnx(array ,sizeof(array)/sizeof(int));
printf(
"Result %d \n",result);
return 0;
}

int findnx(int *array,const int n)
{
int result = array[0];
int times = 1;
int i = 1;
for(;i < n; ++i)
{
if(!times){
result
= array[i];
times
= 1;
}
else{
if(result == array[i])
++times;
else
--times;
}
}
return result;
}

原文地址:https://www.cnblogs.com/westfly/p/2048957.html