Let the Balloon Rise

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 60158    Accepted Submission(s): 22125

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
 
Author
WU, Jiazhi
 
import java.util.*;

public class Main {

	public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
int t=Integer.parseInt(sc.next());
int a[]=new int[1007];
if(t==0)
break;
LinkedList<String> str=new LinkedList<String>();
int count=0;
for(int i=0;i<t;i++){
String color=sc.next();
if(str.contains(color)==false){
str.add(count,color);
a[count]=1;
count++;
}
else{
a[str.indexOf(color)]+=1;
} }
int max=0;
int n=0;
for(int i=0;i<t;i++){
if(a[i]>max){
max=a[i];
n=i;
}
}
System.out.println(str.get(n));
} } }

hdu1004----用java链表实现的更多相关文章

  1. JAVA 链表操作:循环链表

    主要分析示例: 一.循环链表简述 二.单链表循环链表 三.双链表循环链表 一.循环链表简述 循环链表即链表形成了一个循环的结构,尾节点不再指向NULL,而是指向头节点HEAD,此时判定链表的结束是尾节 ...

  2. Java链表基本操作和Java.util.ArrayList

    Java链表基本操作和Java.util.ArrayList 今天做了一道<剑指offer>上的一道编程题“从尾到头打印链表”,具体要求如下:输入一个链表,按链表值从尾到头的顺序返回一个A ...

  3. JAVA链表中迭代器的实现

    注:本文代码出自<java数据结构和算法>一书. PS:本文中类的名字定义存在问题,Link9应改为Link.LinkList9应该为LinkList.由于在同包下存在该名称,所以在后面接 ...

  4. JAVA 链表操作:单链表和双链表

    主要讲述几点: 一.链表的简介 二.链表实现原理和必要性 三.单链表示例 四.双链表示例 一.链表的简介 链表是一种比较常用的数据结构,链表虽然保存比较复杂,但是在查询时候比较便捷,在多种计算机语言都 ...

  5. java 链表数据结构

    首先,单链表相对于队列的优势在于存储地址不是连续的,这样的意义在于,操作其中的某一个位置的元素时不需要对之前的其他元素都进行内存操作,大大的为我们的计算机减压了.下面直接进入正题: 先要定义一个结点类 ...

  6. Java 链表

    按链表的组织形式分有ArrayList和LinkList两种.ArrayList内部其实是用数组的形式实现链表,比较适合链表大小确定或较少对链表进行增删操作的情况,同时对每个链表节点的访问时间都是co ...

  7. 算法_栈与队列的Java链表实现

    链表是一个递归的数据结构,它或者为null,或者是指向一个结点的引用,该结点含有一个泛型的元素和指向另一个链表的引用.可以用一个内部类来定义节点的抽象数据类型: private class Node ...

  8. 学习记录 java 链表知识

    01.import java.util.HashMap; 02.import java.util.Scanner; 03.import java.util.Stack; 04. 05./** 06. ...

  9. Java链表的一些操作:

    [还有一些其他的算法提]http://blog.csdn.net/WalkingInTheWind/article/category/906980 [转]http://blog.csdn.net/lu ...

  10. 面试中的Java链表

    链表作为常考的面试题,并且本身比较灵活,对指针的应用较多.本文对常见的链表面试题Java实现做了整理. 链表节点定义如下: static class Node { int num; Node next ...

随机推荐

  1. c++程序猿经典面试题

    1.请问i的值会输出什么? #include"iostream.h" int i=1; void main() { int i=i; cout<<i<<en ...

  2. Java I/O— 梳理各种“流”

    背景 Java核心库java.io它提供了一个综合IO接口.包含:文件读写.标准装备输出等..Java在IO它是流为基础进行输入输出的.全部数据被串行化写入输出流,或者从输入流读入. -- 百度百科 ...

  3. WebSocket聊天室demo

    根据Socket异步聊天室修改成WebSocket聊天室 WebSocket特别的地方是 握手和消息内容的编码.解码(添加了ServerHelper协助处理) ServerHelper: using ...

  4. Note for video Machine Learning and Data Mining——Linear Model

    Here is the note for lecture three. the linear model Linear model is a basic and important model in ...

  5. spring 定义自己的标签 学习

    自己的自定义配置文件spring 在,有时你想要做一些配置信息的数据结构.基于扩展生意做. 首先: 在项目META-INF文件夹中创建两个文件spring.handlers,和spring.shcem ...

  6. HYSBZ 2243(树链剖分)

    题目连接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28982#problem/D 题意:给定一棵有n个节点的无根树及点权和m个操作, ...

  7. Visual Assist X 快捷键

    Shift+Alt+F Find References 查找引用 Shift+Alt+S FindSynbolDialog 打开查找符号对话框 Alt+G GotoImplementation 在定义 ...

  8. 可兼容IE的jquery.cookie函数方法

    前言 在开发过程中,因为之前有接触过Discuz,就直接拿其common.js里面的getcookie和setcookie方法来使用,做到后面在使用IE来测试的时候,发现这两个方法子啊IE下不起作用, ...

  9. POJ 1276  Cash Machine(多重背包)

    Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24132 Accepted: 8446 Descrip ...

  10. POJ 36666 Making the Grade 简单DP

    题意是: 给出n个数,让你用最小的花费将其改成非递增或非递减的 然后花费就是新序列与原序列各个位置的数的差的绝对值的和 然后可以看到有2000个数,数的范围是10亿 仔细观察可以想象到.其实改变序列中 ...