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

    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. 

    InputInput 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. 
    OutputFor 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

    代码逻辑值得玩味
     1 /*
     2     Name: Let the Balloon Rise
     3     Copyright: 
     4     Author: 
     5     Date: 09/08/17 17:01
     6     Description: 寻找颜色出现次数最多的气球
     7 */
     8 #include<iostream>
     9 #include<algorithm>
    10 #include<cstring>
    11 using namespace std;
    12 int main()
    13 {
    14     int n;
    15     int num[1005];
    16     char ch[1005][20];
    17     while(cin>>n && n)
    18     {
    19         memset(num,0,sizeof(num));
    20         for(int i = 0; i < n; i++)
    21         {
    22             cin>>ch[i];
    23             for(int j = 0; j < i; j++)
    24                 if(strcmp(ch[j],ch[i]) == 0) num[i]++;
    25         }
    26         int max = num[0];
    27         int t = 0;
    28         for(int i = 1; i < n; i++)
    29         {
    30             if(max < num[i])
    31             {
    32                 max = num[i];
    33                 t = i;
    34             }
    35          } 
    36          cout<<ch[t]<<endl;
    37     }
    38      
    39 
    40     return 0;
    41 }
  • 相关阅读:
    iOS 发送位置消息
    集成 jpush-react-native 常见问题汇总 (iOS 篇)
    RESTful API 最佳实践
    RESTful API 设计指南
    理解RESTful架构
    PHP 调用 shell
    Laravel Model updating&updated 事件使用注意事项
    sudo 命令报 unable to resolve host 导致反应速度变慢
    Nginx设置禁止通过IP访问服务器并且只能通过指定域名访问
    Homestead can not mount nfs on macos catalina
  • 原文地址:https://www.cnblogs.com/jj81/p/7326359.html
Copyright © 2011-2022 走看看