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 }
  • 相关阅读:
    单链表反转
    【华为悦读汇】技术发烧友:M-LAG
    Linux系列—策略路由、ip rule、ip route
    对象存储,为什么那么火?
    关于存储技术的最强入门科普
    OpenStack入门科普,看这一篇就够啦!
    虚拟化技术的本质
    师屎胜于熊便:FCoE iSCSI FC组网PK
    懂了!VMware/KVM/Docker原来是这么回事儿
    集群文件系统是什么
  • 原文地址:https://www.cnblogs.com/jj81/p/7326359.html
Copyright © 2011-2022 走看看