若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。


  • 运维

  • 前端

  • 编程

  • 随笔

  • hust-oj

1659: Let the Balloon Rise

发表于 2017-10-06   |   分类于 HUSTOJ   |   阅读次数 1,207

题目描述

Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color and find the result.

This year, they decide to leave this lovely job to you.

输入

Input contains multiple test cases. Each test case starts with a number N (0 < N < 1000) — the total number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to 15 lower-case letters.

A test case with N = 0 terminates the input and this test case is not to be processed.

输出

For each case, print the color of balloon for the most popular problem on a single line. It is guaranteed that there is a unique solution for each test case.

样例输入

5
green
red
blue
red
red
3
pink
orange
pink
0

样例输出

red
pink

参考代码

#include<stdio.h>
#include<string.h>
int main() 
{
    int n,i,j,k,b[1010],max;
    char a[1010][20];
    while(scanf("%d",&n)&&n) 
    {
        getchar();
        for (i=0;i<1010;i++)
                    for (j=0;j<20;j++) 
        {
            a[i][j]=0;
            b[i]=0;
        }
        for (i=0;i<n;i++)
                    scanf("%s",a[i]);
        for (i=0;i<n;i++)
                    for (j=i+1;j<n;j++)
                        if(strcmp(a[j],a[i])==0)
                            b[i]++;
        max=-1;
        for (i=0;i<n;i++)
                    if(b[i]>max) 
        {
            max=b[i];
            k=i;
        }
        printf("%sn",a[k]);
    }
    return 0;
}

解析

暂无

hustoj

发表评论 取消回复

邮箱地址不会被公开。 必填项已用*标注

*
*


hoxis wechat
著作权归作者所有
站点更新说明
  • 文章目录
  • 站点概览
若是凉夜已成梦

若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。

1904 日志
6 分类
12 标签
RSS
weibo github twitter facebook

友情链接

Dreams孤独患者 原站点 Skip
© 2017 若是凉夜已成梦
Powered by WordPress | 已运行
Theme By NexT.Mist