hdu 1029 水题

来源:互联网 发布:python txt 转成xml 编辑:程序博客网 时间:2024/06/05 14:13

这题主要是熟悉下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;}


 

原创粉丝点击