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 }
  • 相关阅读:
    AJAX初步学习
    MyBatis 中@param 的用法
    MyBatis 分页
    MyBatis 中一对一和一对多的映射关系
    MyBatis的增删改查。
    MyBatis配置文件
    java 中 “==” 和 equals 的区别
    点云格式-pcd
    VS2015+VisualSVN+TortoiseSVN安装及使用
    GIS中的引擎:地图引擎
  • 原文地址:https://www.cnblogs.com/jj81/p/7326359.html
Copyright © 2011-2022 走看看