现在的位置: 首页 > 综合 > 正文

hdu 1029 水题

2013年10月06日 ⁄ 综合 ⁄ 共 373字 ⁄ 字号 评论关闭

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

 

抱歉!评论已关闭.