hdu 1029 map做法

来源:互联网 发布:阿里云服务器ip段 编辑:程序博客网 时间:2024/04/30 00:01

Ignatius and the Princess IV

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K (Java/Others)
Total Submission(s): 9654    Accepted Submission(s): 3785


Problem Description
"OK, you are not too bad, em... But you can never pass the next test." feng5166 says.

"I will tell you an odd number N, and then N integers. There will be a special integer among them, you have to tell me which integer is the special one after I tell you all the integers." feng5166 says.

"But what is the characteristic of the special integer?" Ignatius asks.

"The integer will appear at least (N+1)/2 times. If you can't find the right integer, I will kill the Princess, and you will be my dinner, too. Hahahaha....." feng5166 says.

Can you find the special integer for Ignatius?
 

Input
The input contains several test cases. Each test case contains two lines. The first line consists of an odd integer N(1<=N<=999999) which indicate the number of the integers feng5166 will tell our hero. The second line contains the N integers. The input is terminated by the end of file.
 

Output
For each test case, you have to output only one line which contains the special number you have found.
 

Sample Input
51 3 2 3 3111 1 1 1 1 5 5 5 5 5 571 1 1 1 1 1 1
 

Sample Output
351
 
题意:输入n个数 n为奇数 问某个数出现的次数大于等于(N+1)/2的是 哪个 输出来
 
思路 map记录
 
#include<stdio.h>#include<map>#include<iostream>using namespace std;map<int,int>mp;int main(){int i,j,n,N;    while(scanf("%d",&n)!=EOF){N=n;mp.clear();while(n--){scanf("%d",&i);mp[i]++;}map<int,int>::iterator it;printf("cc");for(it=mp.begin();it!=mp.end();i++){if(it->second>=(N+1)/2) {printf("%d\n",it->first);break;}}}return 0;}
 
 
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 宝宝吃过了还闹怎么办 ddrops d3吃多了怎么办 ddrops d3滴多了怎么办 维生素d滴多了怎么办 ddrops最后滴不出来的怎么办 ddrops一次滴3滴怎么办 小孩子头睡偏了怎么办 7岁儿童头睡偏了怎么办 婴儿后脑睡平了怎么办 六个月宝宝免疫力低怎么办 十个月宝宝食烧怎么办 6个月宝宝感冒了怎么办 5个月宝宝腿短怎么办 5个月宝宝太瘦怎么办 宝宝喝了浓奶粉怎么办 一岁把尿不尿怎么办 五个月的宝宝大便干燥怎么办 婴儿便秘怎么办什么方法最有效 8个月小孩便秘怎么办 1个月新生儿便秘怎么办 新生儿头竖立0分怎么办 20天的宝宝便秘怎么办 出生23天的宝宝便秘怎么办 喝奶粉的宝宝便秘怎么办 抱孩子抱的驼背怎么办 4岁宝宝不拉屎怎么办 小朋友大便拉不出来怎么办 儿童便秘拉不出来怎么办 没感冒喉咙有痰怎么办 宝宝喂不进去药怎么办 新生儿只放屁不拉大便怎么办 新生儿腹胀不拉大便怎么办 8月宝宝咳嗽有痰怎么办 2个月婴儿惊吓怎么办 吃了米粉不拉屎怎么办 奇异果奶昔苦了怎么办 8个月宝宝偏瘦怎么办 一岁宝宝螺旋腿怎么办 七个月宝宝晚上咳嗽厉害怎么办 孕7个月感冒咳嗽怎么办 4个月婴儿肺炎怎么办