Football

我个人理解就是,我刚开始输入n,他是个数,那我第一个s1输入,只要接下来不等于就定义为temp+1 等于就定义为count+1,后面输出就行.

题目描述

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 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≤n≤100),表示有 n 次进球,接下来 n 行,每行一个长度不超过 1010,只由大写字母组成的字符串,表示一个进球的球队名,保证只有两个球队。

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

输入输出样例

输入 #1复制

1
ABC

输出 #1复制

ABC

输入 #2复制

5
A
ABA
ABA
A
A

输出 #2复制

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

void solve(int n) {
	int count = 0, temp = 0;
	string s;
	cin >> s;
	string youhua = s, oi;
	count++;
	for (int i = 2; i <= n; i++) {
		cin >> s;
		if (youhua == s) {
			count++;
		} else {
			temp++;
			oi = s;
		}
	}
	if (count > temp) {
		cout << youhua << "\n";
	} else {
		cout << oi << "\n";
	}
}
int main() {
	int n;
	cin >> n;
	solve(n);
	return 0;
}
#include<bits/stdc++.h>
using namespace std;

void solve(int n) {
	int count = 1, temp = 0, m = n - 1;
	string s, oi;
	cin >> s;
	string youhua = s;
	while (m--) {
		cin >> s;
		if (s == youhua) {
			count++;
		} else {
			temp++;
			oi = s;
		}
	}
	string hh = count > temp ? youhua : oi;
	cout << hh << "\n";
}

int main() {
	int n;
	cin >> n;
	solve(n);
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值