这题主要是熟悉下map的写法
AC代码如下:
#include <iostream> #include <map> #include <iterator> #include <cstdio> using namespace std; int main(){ int N; map<int,int> maps; while( scanf( "%d", &N ) != EOF ){ maps.clear(); int i; for( i = 0; i < N; i++ ){ int temp; cin >> temp; if( maps.find( temp ) != maps.end() ){ maps[temp]++; }else{ maps[temp] = 1; } if( maps[temp] >= ( N + 1 ) / 2 ){ cout << temp << endl; break; } } while( ++i < N ){ int temp; cin >> temp; } } return 0; }