码迷,mamicode.com
首页 > 其他好文 > 详细

CF43A Football

时间:2018-02-11 18:06:17      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:guarantee   字符   and   int   find   desc   sample   contains   des   

题意翻译

题目大意

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

第一行一个整数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];
}

 

CF43A Football

标签:guarantee   字符   and   int   find   desc   sample   contains   des   

原文地址:https://www.cnblogs.com/cangT-Tlan/p/8442500.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!