我个人理解就是,我刚开始输入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;
}