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
  • 相关阅读:
    python读取文件报错:pandas.errors.ParserError: iterator should return strings, not bytes (did you open the file in text mode?)
    Python关键字排序
    Python中赋值和print笔记
    python元祖和文件用法举例
    Python 列表和字典用法解释
    python中字符串及字符串的格式化
    python动态类型简介
    Python中关于深复制和浅复制详细解释
    Python中常用数字类型
    python内置对象的一些知识
  • 原文地址:https://www.cnblogs.com/xfjy/p/4991245.html
Copyright © 2011-2022 走看看