zoukankan      html  css  js  c++  java
  • 【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

  • 相关阅读:
    Leetcode-Pascal's Triangle
    SRM 619
    请用漂亮欢呼-------Day38
    创建list方法总结
    [ZJOI2019]语言
    jekyll 在博客添加流程图
    jekyll 在博客添加流程图
    HttpRepl 互操作的 RESTful HTTP 服务调试命令行工具
    HttpRepl 互操作的 RESTful HTTP 服务调试命令行工具
    How to use code to exit the application in UWP
  • 原文地址:https://www.cnblogs.com/xl1027515989/p/3257262.html
Copyright © 2011-2022 走看看