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

  • 相关阅读:
    NGUI的sprite的使用(九宫切图)
    NGUI的button的创建的问题(Button Script)
    NGUI的Lebal需注意问题
    untiy3D-初学NGUI遇到问题
    MVC路由学习:自定义路由参数(用户看不到参数名),重新定义路由规则
    C#设计模式:工厂模式
    C#设计模式:抽象工厂(Abstract Factory)
    2014年计算机求职总结--准备篇
    UVA OJ 10035
    UVa OJ 455 Periodic Strings
  • 原文地址:https://www.cnblogs.com/cccczh/p/5754206.html
Copyright © 2020-2023  润新知