hdu1029

找出数列中出现(N+1)/2次的数,暴力模拟

 1 #include<stdio.h>
 2 #include<map>
 3 using namespace std;
 4 
 5 int main(){
 6     int n;
 7     while(scanf("%d",&n)!=EOF){
 8         map<int,int>m;
 9         int ans=0,tmp=0;
10         for(int i=1;i<=n;++i){
11             int a;
12             scanf("%d",&a);
13             m[a]++;
14             if(m[a]>ans){
15                 ans=m[a];
16                 tmp=a;
17             }
18         }
19         printf("%d\n",tmp);
20     }
21     return 0;
22 }
View Code