POJ 2643 Election map
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 ;
}
POJ 2643 Election map的更多相关文章
- POJ 2643 Election
Election Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3558 Accepted: 1692 Descript ...
- poj 2503 Babelfish(Map、Hash、字典树)
题目链接:http://poj.org/bbs?problem_id=2503 思路分析: 题目数据数据量为10^5, 为查找问题,使用Hash或Map等查找树可以解决,也可以使用字典树查找. 代码( ...
- 【POJ】2296 Map Labeler
http://poj.org/problem?id=2296 题意:题意:给你n个点,每个点上都放一个正方形,点只能在正方形的上边或下边的中点上,所有正方形大小一样,不能有面积重叠,求最大的正方形.( ...
- Catch That Cow POJ - 3278 bfs map超时,短路判断顺序。
题意:可以把n边为n+1,n-1,n*2问从n到k的最少变化次数. 坑:标题写了.有点不会写bfs了... ac代码 #define _CRT_SECURE_NO_WARNINGS #include& ...
- POJ 1002 487-3279(map映照容器的使用)
Description Businesses like to have memorable telephone numbers. One way to make a telephone number ...
- Poj 2503 Babelfish(Map操作)
一.Description You have just moved from Waterloo to a big city. The people here speak an incomprehens ...
- POJ 1002 487-3279 map
487-3279 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 287874 Accepted: 51669 Descr ...
- POJ 2643
#include<iostream> #include<stdio.h> #include<string> #include<algorithm> #d ...
- POJ 3664 Election Time 题解
这道题网上非常多人都会说easy,水题之类的话,只是我看了下说这种话的人的程序,能够说他们的程序都不及格! 为什么呢?由于他们的程序都是使用简单的二次排序水过(大概你能搜索到的多是这种程序).那样自然 ...
随机推荐
- ld: warning: directory not found for option ''
iOS开发中经常遇到这样的警告,如图所示: 原因是存在未用到的目录. 解决方法:选择Build Settings,找到Search Paths中的Library Search Paths,如下图 删除 ...
- 简单聊聊红黑树(Red Black Tree)
前言 众所周知,红黑树是非常经典,也很非常重要的数据结构,自从1972年被发明以来,因为其稳定高效的特性,40多年的时间里,红黑树一直应用在许多系统组件和基础类库中,默默无闻的为我们提供服务,身边 ...
- 夯实Java基础(十三)——字符串
字符串应该是我们在Java中用的最频繁.最多的,可见字符串对于我们来说是多么的重要,所以我们非常有必要去深入的了解一下. 1.String String就代表字符串,在Java中字符串属于对象.我们刚 ...
- 微信小程序如何动态增删class类名达到切换tabel栏的效果
微信小程序和vue还是有点差别的,要想实现通过动态切换class来达到切换css的效果,请看代码: //wxml页面: <view class="tab"> <v ...
- 逛公园[NOIP2017 D2 T3](dp+spfa)
题目描述 策策同学特别喜欢逛公园. 公园可以看成一张 \(N\)个点\(M\) 条边构成的有向图,且没有自环和重边.其中 1号点是公园的入口,N号点是公园的出口,每条边有一个非负权值,代表策策经过这条 ...
- C语言连接mysql,用GCC编译
1. main.c文件内容如下 #include <stdlib.h>#include <stdio.h>#include <winsock.h>#include ...
- 从零写一个编译器(十一):代码生成之Java字节码基础
项目的完整代码在 C2j-Compiler 前言 第十一篇,终于要进入代码生成部分了,但是但是在此之前,因为我们要做的是C语言到字节码的编译,所以自然要了解一些字节码,但是由于C语言比较简单,所以只需 ...
- 并发编程 Semaphore的使用和详解
类Semaphore的基本使用 Semaphore的作用:限制线程并发的数量 课外话题[多线程的同步概念]:其实就是排着队去执行一个任务,执行任务是一个一个的执行,这样的优点是有助于程序逻辑的正确性, ...
- Mac 隐藏、显示文件;移动开发者常用路径
Mac Finder 标题显示文件完整路径 // mac Finder 标题栏显示文件夹完整路径, 把YES改为NO则是不显示 defaults write com.apple.finder _FXS ...
- Spring入门(十):Spring AOP使用讲解
1. 什么是AOP? AOP是Aspect Oriented Programming的缩写,意思是:面向切面编程,它是通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术. 可以认为AOP是 ...