地址:http://acm.bit.edu.cn/mod/programming/view.php?id=657
给一个序列输出出现次数最多的数
用Map做完发现其实只要排序然后从头跑一遍就行了。。又脑残了。。
#include<iostream>
#include<map>
using namespace std;
int main()
{
int n,temp,max,maxn;
while(scanf("%d",&n)!=EOF)
{
map<int,int>m;
map<int,int>::iterator m1;
max=0;
while(n--)
{
scanf("%d",&temp);
if(m.find(temp)==m.end()) m[temp]=1; //若以前未出现过,新建;
else m[temp]++; //否则值(出现次数)+1
}
for(m1=m.begin();m1!=m.end();m1++) //遍历一遍找到值最大的
{
if(m1->second>max) max=m1->second,maxn=m1->first;
}
printf("%d\n",maxn);
}
return 0;
}