HDU 1004 Let the Balloon Rise
来源:互联网 发布:手机抢网络的软件 编辑:程序博客网 时间:2024/04/30 14:28
HDU 1004 Let the Balloon Rise
题意:给你一堆不同颜色的气球,数出什么颜色的气球最多,输出这个气球的名字。
思路:简单的Map题,把所有元素依次装入HashMap里,然后遍历找出value最大的那一项,然后输出对应的key。或者可以用TreeMap改成按值排序。
AC代码:
import java.util.HashMap;import java.util.Scanner;import java.util.Map.Entry;public class Main{static Scanner scan=new Scanner(System.in);public static void main(String[] args){while(scan.hasNext()){int n=scan.nextInt();if(n==0) break;HashMap<String, Integer> hash=new HashMap<String,Integer>();for(int i=0;i<n;i++){String key=scan.next();hash.put(key,hash.get(key)==null?1:hash.get(key)+1);}int max=0;String ans="";for(Entry<String,Integer> entry:hash.entrySet()) if(entry.getValue()>max){max=entry.getValue();ans=entry.getKey();}System.out.println(ans);}}}
0 0
- HDU 1004 Let the Balloon Rise
- HDU 1004 Let the Balloon Rise
- hdu 1004 Let the Balloon Rise
- HDU 1004 Let the Balloon Rise
- HDU--1004 Let the Balloon Rise
- hdu 1004 Let the Balloon Rise
- hdu 1004 Let the Balloon Rise
- HDU 1004 Let the Balloon Rise
- hdu 1004 Let the Balloon Rise
- HDU 1004 Let the Balloon Rise
- HDU 1004 Let the Balloon Rise
- Hdu 1004 - Let the Balloon Rise
- HDU 1004 Let the Balloon Rise
- HDU 1004 Let the Balloon Rise
- HDU--1004--Let the Balloon Rise
- hdu 1004 Let the Balloon Rise
- hdu 1004 Let the Balloon Rise
- HDU 1004 Let the Balloon Rise STL
- 路口掉头
- 食物链
- 关于应对科目三考试
- 海淀驾校科目三考前集训
- 吐梦栋寂诿判源栋某筛中驶捣够俜
- HDU 1004 Let the Balloon Rise
- 海驾上周五当天集训+考试,轻松通过科目三
- Hbase0.96源代码之HMaster(一)
- 论坛---分页和回复
- centos下tomcat+mysql的配置和项目部署
- POJ 1002 487-3279
- 将博客搬至CSDN
- spring MVC 3.2+ 中关于@ResponseBody返回乱码的完美解决方案
- tomcat和jdk在linux下打包部署