CF43A Football

题意翻译

题目大意

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

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

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

Translated by Khassar

题目描述

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 nn 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 nn ( 1<=n<=1001<=n<=100 ) — the number of lines in the description. Then follow nn 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
ABC
输出样例#1: 复制
ABC
输入样例#2: 复制
5
A
ABA
ABA
A
A
输出样例#2: 复制
A

 

思路:因为只有两队,所以只统计一个队伍的成绩即可,总分减去该队伍的成绩就是另一个队伍的成绩。

 

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int n;
int grade[2];
string str,name[2];
int main(){
    scanf("%d",&n);
    cin>>name[0];grade[0]++;
    for(int i=1;i<=n-1;i++) {
        cin>>str;
        if(str!=name[0])    name[1]=str;
        else grade[0]++;
    }
    if(grade[0]>n-grade[0])    cout<<name[0]; 
    else    cout<<name[1];
}

 

posted @ 2018-02-11 16:27  一蓑烟雨任生平  阅读(261)  评论(0编辑  收藏  举报