zoukankan      html  css  js  c++  java
  • HDU1004

    Let the Balloon Rise

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

    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
     
     
     
    1.相同答案输出第一组
    2.strcmp(a[i],c[j])==0
    3.细节处理不到位
    #include<iostream>
    #include<cstdio>
    #include<string.h>
    using namespace std;
    int main()
    {
        int n,l;
        char a[1200][20],c[1200][20];
        int b[1200];
        while(~scanf("%d",&n))
        {
            if (n==0)
                break;
            memset(a,0,sizeof(a));
            memset(c,0,sizeof(c));
            memset(b,0,sizeof(b));
            l=1;
            getchar();
           for (int i=0;i<n;i++)
           {
               gets(a[i]);
           }
           strcpy(c[0],a[0]);
           b[0]=1;
           //puts("");
            //printf("%s
    ",c[0]);
            //printf("%s
    ",a[1]);
           for (int i=1;i<n;i++)
           {
               for (int j=0;j<l;j++)
                {
                    if (strcmp(a[i],c[j])==0)
                    {
                       //cout<<"sss"<<endl;
                       //cout<<i<<endl;
                         //printf("%s
    ",a[i]);
                         //printf("%s
    ",c[j]);
                        b[j]++;
                        break;
                    }
                    if (j==l-1)
                    {
    
                         strcpy(c[l],a[i]);
                         b[l]++;
                         l++;
                         break;
                        //c[l]=a[i];
                        //printf("%s
    ",a[i]);
                        //printf("%s
    ",c[l]);
    
                        //l++;
                    }
               }
           }
          // for (int o=0;o<5;o++)
          //printf("%d  ",b[o]);
            //puts("");
            l++;
            //printf("%d
    ",l);
           int flag=0,k,temp=0;
           for ( k=0;k<l;k++)
           {
               //cout<<"ssss"<<endl;
               if (b[k]>flag)
               {
                   //cout<<"sss"<<endl;
                   flag=b[k];
                   temp=k;
                   //cout<<k<<endl;
               }
           }
           //printf("%d
    ",flag);
           printf("%s
    ",c[temp]);
          //puts("");
        }
        return 0;
    }
    View Code
  • 相关阅读:
    Log4j日志
    Spring和MyBatis环境整合
    Hibernatede的优缺点,Struts的工作流程,延迟加载及理解开闭原则
    Java开发中的23种设计模式
    Spring配置
    Spring框架的一些基础知识
    python打造多线程图片下载工具
    redis 主从备份服务器集群搭建
    mongoo数据库设置权限
    mongo数据库主从备份服务集群搭建
  • 原文地址:https://www.cnblogs.com/xfjy/p/4991245.html
Copyright © 2011-2022 走看看