POJ 2643 Election

第一次写博客,想通过写博客记录自己的ACM历程,也想解释下英文题目,写些自己的理解。也可以让自己以后找题目更加方便点嘛。
Election
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 4491 Accepted: 2100
Description

Canada has a multi-party system of government. Each candidate is generally associated with a party, and the party whose candidates win the most ridings generally forms the government. Some candidates run as independents, meaning they are not associated with any party. Your job is to count the votes for a particular riding and to determine the party with which the winning candidate is associated.
Input

The first line of input contains a positive integer n satisfying 2 <= n <= 20, the number of candidates in the riding. n pairs of lines follow: the first line in each pair is the name of the candidate, up to 80 characters; the second line is the name of the party, up to 80 characters, or the word “independent” if the candidate has no party. No candidate name is repeated and no party name is repeated in the input. No lines contain leading or trailing blanks.
The next line contains a positive integer m <= 10000, and is followed by m lines each indicating the name of a candidate for which a ballot is cast. Any names not in the list of candidates should be ignored.
Output

Output consists of a single line containing one of:
The name of the party with whom the winning candidate is associated, if there is a winning candidate and that candidate is associated with a party.
The word “independent” if there is a winning candidate and that candidate is not associated with a party.
The word “tie” if there is no winner; that is, if no candidate receives more votes than every other candidate.
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
Source

Waterloo local 1999.06.19
这道题的大意是先输入几个参加选举的人员的名字与党派(先名字后党派),然后再输入的是投票,每一行的名字代表有人投了这个人一票。
最后再输出得票最多的人的党派,注无党派就是independent,如果同时有几个人得票最多的话,就输出tie。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
using namespace std;
int main()
{
int t;
cin >> t;
getchar();
map<string,string>mm;
while(t--)//输入参与选举的人与党派
{
char s1[],s2[];
gets(s1);
gets(s2);
mm[s1] = s2;
}
int n;
cin >> n;
getchar();
map<string,int>mn;
while(n--)//输入得到选举票的人
{
char s3[];
gets(s3);
mn[s3]++;
}
string str;
int a=,flag=;
for(map<string,int>::iterator it=mn.begin();it!=mn.end();it++)//找得票最多的人
{
if(it->second>=a)
{
a = it->second;
str = it->first;
}
}
for(map<string,int>::iterator it=mn.begin();it!=mn.end();it++)//判断得票最多的有几个人
{
if(it->second==mn[str])
{
flag++;
}
}
if(flag>=)//如果有多个人就输出tie
printf("tie\n");
else cout << mm[str] << endl;//否则输出其党派
return ;
}

最新文章

  1. js写的ajax
  2. 第一次自己写jquery图片延迟加载插件,不通用,但修改一下还是可以使用到很多页面上的
  3. Box2D淌坑日记: 如何正确的设置角度
  4. 接口测试之HttpClient
  5. node.js在windows环境下的安装
  6. python3使用csv模块读写csv文件
  7. Mcafee两个Mac版本之间的区别
  8. EZ-USB FX2(68013)固件研究
  9. Android网络框架Volley(实战篇)
  10. UVa12096.The SetStack Computer
  11. 自己总结的ruby on rails 查询方法
  12. chip-seq数据分析中peak-calling软件-------MACS的安装
  13. springboot kafka集成(实现producer和consumer)
  14. centos6.9关闭防火墙
  15. MySQL5.7参数log_timestamps
  16. Python compile() 函数
  17. Array对象的方法
  18. 实战体验几种MySQL Cluster方案(转)
  19. UVA-10318 Security Panel (DFS+剪枝)
  20. eclipse中文乱码解决

热门文章

  1. 【iOS】删除 main.storyboard 的问题
  2. 前端笔记之React(六)ES6的Set和Map&amp;immutable和Ramda和lodash&amp;redux-thunk
  3. input属性设置type=&quot;number&quot;之后, 仍可输入e, E, -, + 的解决办法
  4. memcached.c 源码分析
  5. 解决报错:类型“System.Object”在未被引用的程序集中定义。必须添加对程序集“System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”的引用
  6. [nghttp2]压测工具,源码编译并进行deb打包过程
  7. 微信小程序云开发报错解决: Setting data field &quot;openid&quot; to undefined is invalid.
  8. win10 我的电脑下面的六个文件夹的隐藏
  9. JavaWeb——JSP表达式语言(EL)
  10. 分享一个非常好用又好看的终端工具--Hyper (支持windows、MacOS、Linux)