POJ 2643 Election(map)
来源:互联网 发布:重庆时尚频道直播软件 编辑:程序博客网 时间:2024/06/02 07:03
Description
有n位候选人,每位候选人属于一个党派,有m位投票人,每位投票人投这n位候选人之中的一人,问得票最多的党派,如果得票最多的党派不止一个则输出tie
Input
第一行为一整数n表示候选人数,之后2*n行每两行表示一位候选人信息,第一行为候选人姓名,第二行为该位候选人所属党派,然后为一整数m表示投票人数,之后m行每行一个字符串表示该位候选人得到一票
Output
如果得票最多的党派只有一个则输出该党派名称,否则输出tie
Sample Input
3
Marilyn Manson
Rhinoceros
Jane Doe
Family Coalition
John Smith
independent
6
John Smith
Marilyn Manson
Marilyn Manson
Jane Doe
John Smith
Marilyn Manson
Sample Output
Rhinoceros
Solution
简单题,用map会比较简单
Code
#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>#include<map>#include<string>using namespace std;#define maxn 88int n,m;map<string,int>num;map<string,string>party;int main(){ string s1,s2; char c1[maxn],c2[maxn]; while(~scanf("%d",&n)) { gets(c1); for(int i=0;i<n;i++) { gets(c1),gets(c2); s1=c1,s2=c2; party[s1]=s2; } scanf("%d",&m); gets(c1); while(m--) { gets(c1); s1=c1; if(party[s1].size())num[s1]++; } int ans=-1,res=0; for(map<string,int>::iterator it=num.begin();it!=num.end();it++) { if(it->second>ans)ans=it->second,s1=it->first,res=1; else if(it->second==ans)res++; } if(res!=1)cout<<"tie"<<endl; else cout<<party[s1]<<endl; } return 0;}
0 0
- POJ 2643 Election(map)
- POJ 2643 Election ——STL map
- poj 2643 Election
- poj-2643-Election
- poj 2643 Election
- POJ 2643 Election
- POJ 2643 Election
- POJ - 2643 Election
- POJ 2643 Election
- POJ 3905 Perfect Election(2-sat)
- POJ 3905 Perfect Election(2-sat)
- POJ 3905 Perfect Election(2-SAT)
- poj--3905--Perfect Election(2-sat)
- POJ2643 Election(MAP)
- poj2643 Election (map)
- poj 3664 Election Time
- POJ 3905 Perfect Election
- POJ Election Time
- 安卓错误集锦
- poj1654 Area
- sql server 如何批量update数据
- poj 2709 贪心暴搜
- nefuoj-1036:2月29日
- POJ 2643 Election(map)
- hdu 3047 Zjnu Stadium 带权并查集
- 水题 nbut1651 Red packet
- java基础15迭代器
- 第2章 python实战例子
- SlidingMenu的使用
- Docker多主机网络通信详解
- 蓝桥杯 算法提高 棋盘多项式
- OM-Order&Shipping Transactions Status Summary .