HDU 1029 Ignatius and the Princess IV 简单map

简单map

 1 #include<stdio.h>
 2 #include<map>
 3 using namespace std;
 4 int main()
 5 {
 6     int n;
 7     int temp;
 8     map<int,int>a;
 9     map<int,int>::iterator iter;
10     while(scanf("%d",&n)!=EOF)
11     {
12         for(int i=0;i<n;i++) 
13         {
14             scanf("%d",&temp);
15             a[temp]++;           
16         }             
17         for(iter=a.begin();iter!=a.end();iter++)
18             if(iter->second>=(n+1)/2)
19             {
20                 printf("%d\n",iter->first);
21                 break;                         
22             } 
23         a.clear();           
24     }
25 }

 

posted on 2014-04-26 16:35  >_<  阅读(136)  评论(0编辑  收藏  举报

导航