• 【ACM】hdu_1004_Let the Balloon Rise_201308141026-2


    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 ",num);
            if(num>max)
            {
                t=i-1;
            }*/
            //printf("%d %d ",t,max);
            printf("%s ",str[t]);
            //for(i=0;i<n;i++)
            //printf("%s ",str[i]);
        }
        return 0;
    }

    //AC

  • 相关阅读:
    Node 之 Express 4x 骨架详解
    Express中app.use()用法 详解
    纯手打AJAX,还有一个对象转查询字符串的小方法obj=>url
    简单node服务器demo,麻雀虽小,五脏俱全
    node环境下多种方式“get数据解析”
    module.exports与exports,export与export default的区别
    2019年9月Github上最热门的JavaScript开源项目
    基于Node 的http转发demo,项目中请使用express+http-proxy-middleware
    HTTP/2 新特性总结
    TensorFlow 8 bit模型量化
  • 原文地址:https://www.cnblogs.com/xl1027515989/p/3257262.html
Copyright © 2020-2023  润新知