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

  • 相关阅读:
    “三路九招”打赢电商低成本营销战
    我的文章分类
    ResourceBundle读取中文properties文件问题
    敏捷基础知识
    一个简单方法:构造xml的document,并将其转换为string
    在android源码环境下写上层应用的一个初步解决方法
    Linux 与 unix shell编程指南——学习笔记
    git 分支的基本操作
    使用repo的本地开发流程
    Linux常用命令收集
  • 原文地址:https://www.cnblogs.com/xl1027515989/p/3257262.html
Copyright © 2011-2022 走看看