hdu 1029 Ignatius and the Princess IV

链  接 :点击打开链接

题 意  :求出现次数最多的数

代  码 :

#include<iostream>
#include<algorithm>
#include<memory.h>
using namespace std;
int a[1000000]; 
int main()
{
	int n;
	while(cin>>n)
	{
		int i,m,max=-1,t;
		memset(a,0,sizeof(a));
		for(i=0;i<n;i++)
		{
			cin>>m;
			a[m]++;
		}
		for(i=0;i<1000000;i++)
		{
			if(a[i]>max) {
				max=a[i];
				t=i;
			}
		}
		cout<<t<<endl;
	}
}


posted @ 2017-02-08 18:20  X_na  阅读(89)  评论(0)    收藏  举报