zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    【二分匹配】【匈牙利算法即由增广路求最大匹配模板】
    【字符串入门专题1】【hdu4763】【未ac题】【扩展kmp exkmp】
    【字符串入门专题1】hdu3613 【一个悲伤的exkmp】
    【如何用XAMPP搭建Wordpress建站环境】
    面向过程要素
    当前阶段--可确定--完善版--学习结构--2016.09.10
    什么时候用工厂模式-----转载
    《EffectiveJava中文版》
    《ARM LINUX内核源码解析》
    《深入分析javaweb技术内幕》
  • 原文地址:https://www.cnblogs.com/love-sherry/p/6745115.html
Copyright © 2011-2022 走看看