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

    Let the Balloon Rise

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 90656    Accepted Submission(s): 34463

     

    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
     


    Source
     


    Recommend
    JGShining   |   We have carefully selected several similar problems for you:  1006 1071 1007 1022 1032 
     
     
    水题,运用字符串函数可以很轻松地解决问题,使用了标记的思想。
    题意:第一个数字代表气球个数,后面的字符串表示气球的颜色,输出颜色出现次数最多的颜色,结果保证只有一种。
    附上代码:
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 using namespace std;
     5 int main()
     6 {
     7     char str[1005][20];
     8     int n,m,i,j,s[1005],t;
     9     while(~scanf("%d",&n)&&n)
    10     {
    11         for(i=0; i<n; i++)
    12             scanf("%s",str[i]);  //输入字符串,用str数组存起来
    13         memset(s,0,sizeof(s));
    14         int max=0;          //记录最后出现最大的次数
    15         for(i=0; i<n; i++)
    16         {
    17             for(j=i+1; j<n; j++)
    18                 if(strcmp(str[i],str[j])==0)  //strcmp函数比较两个字符串是否相同
    19                     s[i]++;   //标记每种颜色出现的次数
    20             if(s[i]>max)
    21             {
    22                 max=s[i];
    23                 t=i;         //记录出现最大次数的颜色位置
    24             }
    25         }
    26         printf("%s
    ",str[t]);
    27     }
    28 }
     
  • 相关阅读:
    考研打卡_Day049
    考研打卡_Day048
    【生活】2017 开始!
    朝花夕拾-android 自定义toast
    朝花夕拾-android 获取当前手机的内存卡状态和网络连接状态
    android media server 解析1-media player service 结构部分
    android binder 进程间通信机制6-Binder进程间通信机制的JAVA接口
    android binder 进程间通信机制5-Service注册和代理对象的获取
    android binder 进程间通信机制4-Service Manager
    android binder 进程间通信机制3-Binder 对象生死
  • 原文地址:https://www.cnblogs.com/pshw/p/4754452.html
Copyright © 2011-2022 走看看