• 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
  • 相关阅读:
    专用学习笔记
    百度地图API试用--(初次尝试)
    学习进度条
    AAAA
    HBase集成(准备篇)
    软件工程学期总结
    【操作系统】实验四 主存空间的分配和回收
    《构建之法》8、9、10章
    金融计算器app的下载情况
    操作系统 实验三 进程调度模拟程序
  • 原文地址:https://www.cnblogs.com/xfjy/p/4991245.html
Copyright © 2020-2023  润新知