• hdu-1004 Let the Balloon Rise


    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004

    题目:

    Let the Balloon Rise

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 119039    Accepted Submission(s): 46654


    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
     
    题意概括:
    给出N个颜色的气球,输出那种颜色的气球数目最多(输出n个字符串中出现的次数最多的);
    解题思路:
    通过结构体组判断那个下标的结构体出现的次数最多。
    AC代码:
    # include <stdio.h>
    # include <string.h>
    
    struct{
        char name[50];
        int n,l;
    }co[1010];
    
    int main ()
    {
        int n,i,j,max,num;
        while(scanf("%d",&n),n)
        {
            getchar();
            for(i=0;i<n;i++)
            {
                 gets(co[i].name);
                 co[i].l=strlen(co[i].name);
                 co[i].n=1;
            }
            max=0;num=0;
            for(i=0;i<n;i++)
            {
                for(j=i+1;j<n;j++)
                {
                    if(co[i].l==co[j].l && strcmp(co[i].name,co[j].name)==0)
                        co[i].n++;
                }
                if(max<co[i].n)
                {
                     max=co[i].n;
                     num=i;
                }
            }
            puts(co[num].name);
        }
        return 0;
    }
  • 相关阅读:
    jsp中的contentType与pageEncoding的区别和作用
    HashMap实现原理及源码分析
    JAVA使用urlrewrite实现伪静态化
    java动态代理(JDK和cglib)
    Codeforces 1201D. Treasure Hunting
    Codeforces 1201C. Maximum Median
    Codeforces 1229C. Konrad and Company Evaluation
    Codeforces 1229B. Kamil and Making a Stream
    Codeforces 1229A. Marcin and Training Camp
    P1315 观光公交
  • 原文地址:https://www.cnblogs.com/love-sherry/p/6745115.html
Copyright © 2020-2023  润新知