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

  • 相关阅读:
    OpenMP并行程序设计
    Snmp在Windows下的实现WinSNMP编程原理
    利用C#开发基于snmpsharpnet基础的SNMP开发应用
    SNMP用VC实现的方法
    题目
    C# combox问题
    网络管理Snmp
    error BK1506
    响应activex事件
    使用C# 连接不同版本的Oracle.DataAccess
  • 原文地址:https://www.cnblogs.com/cccczh/p/5754206.html
Copyright © 2011-2022 走看看