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 
  • 相关阅读:
    每日一题力扣222 完全二叉树节点的个数
    236 二叉树的最近公共祖先
    每日一题力扣122
    每日一题力扣 100 相同的树
    每日一题力扣617 合并二叉树
    每日一题力扣226
    每日一题力扣101 对称子树
    腾讯 qq 与 360 打架, 腾讯qq 无理
    决定把 blog 从 csdn.net 迁移到 cnblogs.com
    发现 google 网站管理员工具中给出的 javascript 代码是错误的
  • 原文地址:https://www.cnblogs.com/dshn/p/4754466.html
Copyright © 2011-2022 走看看