zoukankan      html  css  js  c++  java
  • 杭电ACM1004

    Let the Balloon Rise

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

    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
     1 #include <stdio.h>
     2 #include <string.h>
     3 
     4 int main()
     5 {
     6     int N=1,max,e,i,j;
     7     char color[1010][15];
     8     int count[1010]={1};
     9     while(scanf("%d",&N)!=EOF&&N)
    10     {
    11         for(i=0;i<N;i++)
    12             scanf("%s",color[i]);
    13         for(i=0;i<N-1;i++)
    14             {
    15                 for(j=i+1;j<N;j++)
    16                 {
    17                     if(strcmp(color[i],color[j])==0)
    18                         count[i]++;
    19                 }
    20             }
    21         max=count[0];e=0;
    22         for (i=1;i<N;i++)
    23         {
    24             if (max<count[i]) e=i;
    25         }
    26         printf("%s
    ",color[e]);
    27     }
    28     return 0;
    29 }

    关键点在于一开始就定义char color[1010][15],而不是char color[N][15]。毕竟不是C99标准,这样一开始就给出足够大的空间,反而更简单。

  • 相关阅读:
    ImageLoader
    Matrix(单点移动,多点缩放)
    自定义各种图形
    自定义圆形图片
    将博客搬至CSDN
    拉格朗日乘子法的证明
    周志华《机器学习》课后答案——第4章.决策树
    [转] 现实•理论•证据──谈如何做研究和写论文
    高维度下的数据科学——线性空间(下)
    线性模型——异方差、序列相关、多重共线性与内生性的处理
  • 原文地址:https://www.cnblogs.com/cccczh/p/5754206.html
Copyright © 2011-2022 走看看