POJ2643 Election(MAP)
来源:互联网 发布:淘宝双11红包怎么用 编辑:程序博客网 时间:2024/05/18 16:39
题目大意:就是n对数据,上面一个是候选人姓名,下面一个是候选人党派,有个自由党也姑且当做一个特殊党派吧。然后m个数据是选票结果,求最后得胜者,得胜的要求是:其票数大于任何一个人。
思路:这道水题需要注意几个地方:The word "tie" if there is no winner; that is, if no candidate receives more votes than every other candidate. 不大于其余所有的人的票数就tie,即是说,赢得条件是要大于其余所有人的票数,即是说最大的数只能有一个。 还有一个要注意的是:Any names not in the list of candidates should be ignored. 也就是说还要下面票数的人如果是上面有过的名字才自加。但是这道题的数据很弱,第二个问题不处理居然也能过。
AC program:#include<iostream>#include<stdio.h>#include<string.h>#include<string>#include<algorithm>#include<math.h>#include<iomanip>#include<queue>#include<map>using namespace std;int main(){map<string ,string>mm;map<string ,int >gg;int n,m;string str1,str2; cin>>n;getchar();while(n--){ getline(cin,str1); getline(cin,str2); mm[str1]=str2; }cin>>m;getchar();bool flag=false;int max=0,tmp; string tag;while(m--){ getline(cin,str1); if(mm[str1].size()==0)continue;///note!!!! mm[str1]==""also ok tmp=++gg[str1]; if(tmp>max){flag=true;max=tmp;tag=str1;} else if(tmp==max){flag=false;} }if(flag){cout<<mm[tag]<<endl;}else cout<<"tie"<<endl;system("pause"); return 0;}
- POJ2643 Election(MAP)
- poj2643 Election (map)
- poj2643 map
- POJ2643-map
- poj2643(map+字典树)
- POJ 2643 Election(map)
- POJ 2643 Election ——STL map
- Election
- Election
- Election Time
- 1967: Election
- Election Time
- Election方法1
- Election方法2
- fjnu 1571 Election
- pku3664 Election Time
- 补缺选举 by-election
- zoj 1854 Election
- 淡淡的微笑,静悄悄地过
- eclipse下把所有的文件都转换为UTF-8的方法
- 开发笔记1-开发遇到的问题和需要自己提高的地方
- 基于XML方式的Bean装配实例
- SQL的数据操作学习(二)
- POJ2643 Election(MAP)
- InnoDB多版本(MVCC)实现简要分析
- 随想录(C++下多线程的创建)
- 一些常识--大部分IT人不知道
- 大小端模式和处理器
- 漫谈sscanf高级特性
- lisp之线性递归和迭代
- 8069---哈夫曼树--模板
- 杭电OJ——1087 Super Jumping! Jumping! Jumping!