![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 #include<iostream> 2 #include<vector> 3 #include<algorithm> 4 using namespace std; 5 6 int main() 7 { 8 int odd; 9 while(cin >> odd) 10 { 11 int x; 12 vector<int> ivec; 13 for(int i = 0; i < odd; ++i) 14 { 15 cin >> x; 16 ivec.push_back(x); 17 } 18 sort(ivec.begin(), ivec.end()); 19 int count = 1, max = 0; 20 x = ivec[0]; 21 int i; 22 for(i = 1; i < ivec.size(); ++i) 23 { 24 if(ivec[i] == ivec[i-1]) 25 ++count; 26 else if(count > max) 27 { 28 max = count; 29 x = ivec[i-1]; 30 if(max >= (odd + 1) / 2) 31 break; 32 } 33 } 34 if(i == ivec.size() && count >= (odd + 1) / 2) 35 x = ivec[ivec.size()-1]; 36 cout << x << endl; 37 } 38 return 0; 39 }