1029
来源:互联网 发布:淘宝无线端新品上架 编辑:程序博客网 时间:2024/05/21 19:34
stl水过
值得一提的是这道题规定大于等于一般,所以有种更好的方法,就是加减,结果的值一定大于等于0;
#include <iostream>
#include <map>
using namespace std;
int main(){
map<int ,int> hash;
int n,tmp;
while(~scanf("%d",&n)){
hash.clear();
for(int i=0; i<n; ++i){
scanf("%d",&tmp);
++hash[tmp];
}
map<int,int>::iterator it;
for(it=hash.begin(); it!=hash.end(); ++it){
if(it->second>=(n+1)/2){
cout<<it->first<<endl;
break;
}
}
}
}
好方法:
#include<iostream>
int main()
{
int i,n,num,currnum,ans;
while(scanf("%d",&n)!=EOF)
{
scanf("%d",&num);
currnum = num;
ans = 1;
for(i = 1 ; i < n; i ++)
{
scanf("%d",&num);
if(ans == 0)
currnum = num,ans ++;
else if(num != currnum)
{
ans --;
}
else if (num == currnum)
ans ++;
}
printf("%d/n",currnum);
}
return 0;
}
- 1029
- 1029
- 1029
- 1029
- 1029
- 1029
- 1029
- 1029
- 1029
- problem 1029
- hdu 1029
- Ural 1029
- sicily 1029
- zoj 1029
- hdu 1029
- HDU 1029
- poj 1029
- hdu 1029
- .NET 实现Eval(文字列表达式计算)的3种实现方法。
- 揭露360真相的帖子
- ubuntu下shell脚本运行异常:bash和dash的区别
- 动态规划--计划一个公司聚会
- 【每日一文101106】新的开始
- 1029
- 自动获得internet时间并更新系统时间
- 关于C++虚析构函数
- Linq to SharePoint 之 parameters的使用
- 社交网数据库技术分析
- LU算法
- 换行符‘/n’和回车符‘/r’ 以及 ASCII码表
- 配置完了要设置conky自启动问题
- vrml 虚拟现实语言设计