zoukankan      html  css  js  c++  java
  • HDU1004Let the Balloon Rise

    Let the Balloon Rise

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


    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
     

     

    Source
     
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <algorithm>
    using namespace std;
    char a[1005][20];
    int num[1005];
    int ii;
    int main()
    {
        int n;
        while(~scanf("%d",&n))
        {
            if(n==0)
            break;
            int maxs=-1;
            for(int i=0;i<n;i++)
            {
                scanf("%s",a[i]);
            }
            for(int i=0;i<n-1;i++)
            {
                int t=0;
                for(int j=i+1;j<n;j++)
                {
                    if(!strcmp(a[i],a[j]))
                    {
                        t++;
                    }
                }
                if(t>maxs)
                {
                    maxs=t;
                    ii=i;
                    //strcpy(b,a[i]);   //不能用,,
                }
            }
            printf("%s
    ",a[ii]);
        }
    }

     

    Recommend
    JGShining   |   We have carefully selected several similar problems for you:  1002 1008 1005 1019 1021 
  • 相关阅读:
    作业5,6 2019/10/23
    作业1、2、3、4 2019/10/23
    实现Map传参Mybatis
    maven工程配置pom.xml实现mybatis的访问数据库操作
    测试
    Postman篇之命令行测试
    unittest框架
    测试
    测试
    测试
  • 原文地址:https://www.cnblogs.com/dshn/p/4754466.html
Copyright © 2011-2022 走看看