Let the Balloon Rise
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 58404    Accepted Submission(s): 21430

Problem Description
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
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.

Output
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.

Sample Input
5
green
red
blue
red
red
3
pink
orange
pink
0

Sample Output
red
pink

Author
WU, Jiazhi

#include <stdio.h>
#include <stdlib.h>

char str[1010][18];

int cmp(const void *a,const void *b)
{
    return strcmp((char *)a,(char *)b);
}
int main()
{
    int n;
    while(scanf("%d%*c",&n),n)
    {
        int i,j,t,max,num;
        char s[18];
        memset(str,0,sizeof(str));
        for(i=0;i<n;i++)
        scanf("%s",str[i]);
        qsort(str,n,sizeof(str[0]),cmp);
       
        strcpy(s,str[0]);
        max=0;num=0;t=0;
        for(i=0;i<=n;i++)
        {
            if(strcmp(s,str[i])==0)
            num++;
            else
            {
                if(num>max)
                {
                max=num;
                t=i-1;
                }
                strcpy(s,str[i]);
                num=1;
            }
        }
        /*printf("%d\n",num);
        if(num>max)
        {
            t=i-1;
        }*/
        //printf("%d %d\n",t,max);
        printf("%s\n",str[t]);
        //for(i=0;i<n;i++)
        //printf("%s\n",str[i]);
    }
    return 0;
}

//AC

【ACM】hdu_1004_Let the Balloon Rise_201308141026-2的更多相关文章

  1. 【ACM】hdu_1004_Let the Balloon Rise

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  2. 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”

    按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...

  3. 【ACM】HDU1008 Elevator 新手题前后不同的代码版本

    [前言] 很久没有纯粹的写写小代码,偶然想起要回炉再来,就去HDU随便选了个最基础的题,也不记得曾经AC过:最后吃惊的发现,思路完全不一样了,代码风格啥的也有不小的变化.希望是成长了一点点吧.后面定期 ...

  4. 【ACM】魔方十一题

    0. 前言打了两年的百度之星,都没进决赛.我最大的感受就是还是太弱,总结起来就是:人弱就要多做题,人傻就要多做题.题目还是按照分类做可能效果比较好,因此,就有了做几个系列的计划.这是系列中的第一个,解 ...

  5. 【ACM】那些年,我们挖(WA)过的最短路

    不定时更新博客,该博客仅仅是一篇关于最短路的题集,题目顺序随机. 算法思想什么的,我就随便说(复)说(制)咯: Dijkstra算法:以起始点为中心向外层层扩展,直到扩展到终点为止.有贪心的意思. 大 ...

  6. 【Acm】算法之美—Crashing Balloon

    题目概述:Crashing Balloon On every  June 1st, the Children's Day, there will be a game named "crash ...

  7. 【ACM】不要62 (数位DP)

    题目:http://acm.acmcoder.com/showproblem.php?pid=2089 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新 ...

  8. 【Acm】八皇后问题

    八皇后问题,是一个古老而著名的问题,是回溯算法的典型例题. 其解决办法和我以前发过的[算法之美—Fire Net:www.cnblogs.com/lcw/p/3159414.html]类似 题目:在8 ...

  9. 【ACM】hud1166 敌兵布阵(线段树)

    经验: cout 特别慢 如果要求速度 全部用 printf !!! 在学习线段树 内容来自:http://www.cnblogs.com/shuaiwhu/archive/2012/04/22/24 ...

随机推荐

  1. eclipse----快速设置主题色

  2. C#内容格式刷html 转成txt

    /// <summary> /// 内容格式刷 /// </summary> /// <param name="strHtml">要格式的文本& ...

  3. IIS Express 错误提示汇总

    在做WEB Service开发中,要经常用到IIS Express服务器,有些自己遇到的问题做一个汇总以待后续查找. 错误类型: 问题来源:直接在项目上选择调试运行. 解决方案: 1.直接找到那个文件 ...

  4. mysql简单增删改查(CRUD)

    先描述一下查看表中所有记录的语句以便查看所做的操作(以下所有语句建议自己敲,不要复制以免出错): user表,字段有 id, name,age,sex:id为主键,自增,插入时可以写 NULL 或者 ...

  5. python算数运算符

    ---恢复内容开始--- 加减乘除 >>> 1+1 2 >>> 4-2 2 >>> 2*5 10 >>> 8/2 4.0 > ...

  6. Android互动设计-蓝牙遥控自走车iTank

    一.让Android与外部的设备互动 iTank智能型移动平台基本款简介 iTank智能型移动平台是一台履带车,车体上方的控制板有一颗微处理器,我们可以通过它的UART或是I2C接口下达指令来控制iT ...

  7. iframe监听unload事件

    阻止默认事件 event.preventDefault(); 阻止事件冒泡 event.stopPropagation(); event.cancelBubble = true; //IE <a ...

  8. CaffeMFC:caffe.pb.h(2525): error C2059: syntax error : 'constant'

    下边的语句会报 syntax error : 'constant'. static const DimCheckMode STRICT = V1LayerParameter_DimCheckMode_ ...

  9. Nginx+nagios安装配置

    Nginx+nagios安装配置 [root@Nagios ~]# vi /etc/nginx/nginx.conf server { listen ; server_name localhost; ...

  10. (转) Hibernate注解开发

    http://blog.csdn.net/yerenyuan_pku/article/details/70162268 Hibernate注解开发 在Hibernate中我们一般都会使用注解,这样可以 ...