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标准,这样一开始就给出足够大的空间,反而更简单。

  • 相关阅读:
    Spring中这么重要的AnnotationAwareAspectJAutoProxyCreator类是干嘛的?
    Spring到底应该学哪些内容?
    如何评价《Java 并发编程艺术》这本书?
    在腾讯工作是一种怎样的体验?
    图解 HTTP 连接管理
    42 张图带你撸完 MySQL 优化
    我是如何进入腾讯的?
    《计算机网络 PDF》搞起!
    JSR
    RelationNet:学习目标间关系来增强特征以及去除NMS | CVPR 2018
  • 原文地址:https://www.cnblogs.com/cccczh/p/5754206.html
Copyright © 2011-2022 走看看