CF43A Football 题解

题目

链接

https://www.luogu.com.cn/problem/CF43A

字面描述

题面翻译

题面描述

两只足球队比赛,现给你进球情况,问哪支队伍赢了。

第一行一个整数 n n n 1 ≤ n ≤ 100 1\leq n\leq 100 1n100),表示有 n n n 次进球,接下来 n n n 行,每行一个长度不超过 10 10 10,只由大写字母组成的字符串,表示一个进球的球队名,保证只有两个球队。

输出一个字符串表示胜利球队的球队名,不会平局。

题目描述

One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn’t find the overall score of the match; however, he got hold of a profound description of the match’s process. On the whole there are $ n $ lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.

输入格式

The first line contains an integer $ n $ ( $ 1<=n<=100 $ ) — the number of lines in the description. Then follow $ n $ lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.

输出格式

Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.

样例 #1

样例输入 #1
1
ABC
样例输出 #1
ABC

样例 #2

样例输入 #2
5
A
ABA
ABA
A
A
样例输出 #2
A

代码实现

map的一道基础操作模板题,(稍后会写map的数据结构介绍)

#include<bits/stdc++.h>
using namespace std;

int t,cnt;
string a,ans;
map<string,int>mp;
map<string,int>::iterator it;
int main(){
	cin>>t;
	while(t--){
		cin>>a;
		mp[a]++;
	}
	for(it=mp.begin();it!=mp.end();it++){
		if(it->second > cnt){
			cnt=it->second;
			ans=it->first;
		}
	}
	cout<<ans<<endl;
	return 0;
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

materialistOier

我只是一名ssfoier

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值