首页 > 编程语言 > 详细

寻找发帖水王(找出数组出现超过一半的数字)

时间:2015-04-12 17:47:38      阅读:255      评论:0      收藏:0      [点我收藏+]
#include<iostream>
using namespace std;
void find(int A[],int length)
{
int times=0;
int i=0;
int temp;
for(;i<length;++i)
{
if(times==0)
{
temp=A[i];
times=1;
}
else
{
if(A[i]==temp)
times++;
else
times--;
}
}
cout<<temp<<endl;
}
int main()
{
int a[]={1,1,1,2,2,2};
find(a,5);
system("pause");
return 0;
}

寻找发帖水王(找出数组出现超过一半的数字)

原文:http://blog.csdn.net/qq_22335577/article/details/45011419

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!