zoukankan      html  css  js  c++  java
  • Let the Balloon Rise

    Problem Description

    Contest time again! How excited it is to see balloonsfloating around. But to tell you a secret, the judges' favorite time isguessing the most popular problem. When the contest is over, they will countthe 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 casestarts with a number N (0 < N <= 1000) -- the total number of balloonsdistributed. The next N lines contain one color each. The color of a balloon isa string of up to 15 lower-case letters.
    A test case with N = 0 terminates the input and this test case is not to beprocessed.

    Output

    For each case, print the color of balloon for the mostpopular problem on a single line. It is guaranteed that there is a uniquesolution for each test case.

    Sample Input

    5
    green
    red
    blue
    red
    red
    3
    pink
    orange
    pink
    0

    Sample Output

    red
    pink

     1 #include <stdio.h> 
     2 #include <string.h>
     3 #define N 1001
     4 
     5 int main(){
     6     int number;
     7     char temp[16];    //temp存放输入的颜色
     8     char color[N][16];  //color所有不同的颜色
     9     int amount[N];   //amount存放所有不同颜色的数量
    10     int i;
    11     int j;
    12     int k;   //k为不同颜色的数量
    13     int max;
    14     int flag;
    15 
    16     while(1){
    17         scanf("%d",&number);
    18 
    19         if(number==0)
    20             break;
    21 
    22         for(i=0;i<number;i++)
    23             amount[i]=0;
    24 
    25         k=0; 
    26         for(i=0;i<number;i++){
    27             scanf("%s",temp);
    28 
    29             if(i==0){
    30                 strcpy(color[0],temp);
    31                 k++;
    32                 continue;
    33             }
    34 
    35             for(j=0;j<k;j++){
    36                 if(strcmp(temp,color[j])==0){
    37                     amount[j]++;
    38                     break;
    39                 }
    40             }
    41 
    42             if(j==k){
    43                 strcpy(color[k],temp);    
    44                 k++;
    45             }
    46         }
    47 
    48         max=amount[0];
    49         flag=0;
    50         for(i=0;i<k;i++){
    51             if(amount[i]>max){
    52                 max=amount[i];
    53                 flag=i;
    54             }
    55         }
    56 
    57         printf("%s
    ",color[flag]);
    58     }
    59     
    60     return 0;
    61 }
  • 相关阅读:
    摘金奇缘在线观看迅雷下载
    无敌破坏王2:大闹互联网在线观看
    神奇动物:格林德沃之罪电影在线观看
    你好,之华
    毒液:致命守护者
    apache 通过ajp访问tomcat多个站点
    docker使用大全 tomcat安装
    Log4j2 + Maven的配置文件示例详解
    centos7 设置tomcat自启动
    nginx多站路由配置tomcat
  • 原文地址:https://www.cnblogs.com/zqxLonely/p/4054522.html
Copyright © 2011-2022 走看看