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

  • 相关阅读:
    共用体类型,结构体类型
    动态内存分配与指向它的指针变量
    向上转型,向下转型
    枚举类型中的构造方法、成员方法
    由setTimeout()里的this引出的this
    eclipse快捷键
    js中运算符的优先级
    关于js闭包杂记
    sublime在Mac osx下安装z-codeing(即emmet)
    利用js得到某个范围内的整数随机数
  • 原文地址:https://www.cnblogs.com/cccczh/p/5754206.html
Copyright © 2011-2022 走看看