博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【杭电ACM】1004 Let the Balloon Rise
阅读量:5996 次
发布时间:2019-06-20

本文共 2110 字,大约阅读时间需要 7 分钟。

开始写技术博客了。

发发自己写的ACM的练习题。

 杭电ACM1004    Let the Balloon Rise

 http://acm.hdu.edu.cn/showproblem.php?pid=1004

 

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
 
1 //author:pz 2  3 import java.util.ArrayList; 4 import java.util.Scanner; 5  6 public class Main{ 7  8   public static void main(String args[]){ 9   Scanner scan = new Scanner(System.in);10   while(scan.hasNextInt()){11     int n = scan.nextInt();12     if(n == 0)13       break;14     ArrayList
color = new ArrayList
();15     ArrayList
count = new ArrayList
();16     String c = scan.next();17     color.add(c);18     count.add(1);19     String modeColor=c;20     Integer modeCount=1;21     while(--n > 0){22       String s = scan.next();23       if(color.contains(s)){24         count.set(color.indexOf(s),count.get(color.indexOf(s))+1);25         if(count.get(color.indexOf(s)) > modeCount){26           modeColor = s;27           modeCount = count.get(color.indexOf(s));28         }29       }30       else{31         color.add(s);32         count.add(1);33       }34     }35     System.out.println(modeColor);36   }37 }38 }

 

 

转载于:https://www.cnblogs.com/pengzheng/archive/2013/04/09/3009244.html

你可能感兴趣的文章
alpha版、beta版、rc版的意思
查看>>
genymotion2.8.1安装apk时提示ARM……x86……异常处理
查看>>
《设计模式系列》---责任链模式
查看>>
map
查看>>
用户空间和内核空间
查看>>
如何写一个完善的c++异常处理类
查看>>
URI和URL的区别
查看>>
C笔记
查看>>
20141021 journey
查看>>
windows7 32位安装easy_intall
查看>>
centos6.x搭建vsftp
查看>>
Take Me To Your Heart让我靠近你心
查看>>
第一部分 思科九年 一(2)
查看>>
人工智能教程020:创建卷积神经网络进阶(11)
查看>>
问题解决之道:网页浏览很慢、卡,Flash老提示崩溃
查看>>
HTML5转换工具Crocodoc
查看>>
怎样修改Eclipse注释的作者
查看>>
ESXI 克隆之后重启网卡报错:CentOS Device does not seem to be present
查看>>
kettle初探
查看>>
下载图片 完整性判断
查看>>