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 }
  • 相关阅读:
    随意给一组数,找出满足一下条件的a[i],a[i]左边的数小于等于a[i],a[i]右边的数大于等于a[i]
    SVN
    四种进程或线程同步互斥的控制方法
    二叉树转双向链表
    最大连续子序列和
    找出一个字符串中第一个只出现一次的字符
    清除浮动的那些事
    jQuery中ready与load事件的区别
    css 经典布局之圣杯布局(左右固定,中间自适应)
    window.name + iframe跨域实例
  • 原文地址:https://www.cnblogs.com/zqxLonely/p/4054522.html
Copyright © 2011-2022 走看看