简单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 ",iter->first); 21 break; 22 } 23 a.clear(); 24 } 25 }