题目来源:杭电acm1004
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
这里使用hashMap,ArrayList集合。源程序如下:
import java.util.*;
public class P1004 { public static void main(String args[]){ int count; String color; Map map = new HashMap<String,Integer>(); Scanner sin = new Scanner(System.in); ArrayList<String> name = new ArrayList<String>(); count = sin.nextInt(); while(count!=0){ for(int i=0;i<count;i++){ color = sin.next(); if(map.containsKey(color)){ Integer tempNum = (Integer)map.get(color); tempNum = tempNum + 1; map.remove(color); map.put(color, tempNum); } else{ map.put(color, new Integer(1)); name.add(color); } } String maxColor = name.get(0); int max = (Integer)map.get(maxColor); name.remove(0); while(!name.isEmpty()){ if(max<(Integer)map.get(name.get(0))){ maxColor = name.get(0); max = (Integer)map.get(maxColor); } name.remove(0); } System.out.println(maxColor); name.clear(); map.clear(); count = Integer.parseInt(sin.next()); } } }
|
相关推荐
#include #include int main(){ int n,a[1001],i,j,k,m,max; char str[1001][16],str1[1001][16]; while(scanf("%d",&n)!=EOF,n) { getchar();
杭州电子科技大学acm第1004题 let the balloon rise
杭电ACM分类杭电ACM分类杭电ACM分类杭电ACM分类
杭电离散答案 杭电离散答案 杭电离散答案 杭电离散答案
考研杭电数据结构试卷
杭电概率论期末试卷杭电概率论期末试卷杭电概率论期末试卷杭电概率论期末试卷杭电概率论期末试卷杭电概率论期末试卷杭电概率论期末试卷杭电概率论期末试卷杭电概率论期末试卷杭电概率论期末试卷杭电概率论期末试卷...
杭电 金工实习报告 杭电 金工实习报告 杭电 金工实习报告
杭电 嵌入式 复习资料 杭电 嵌入式 复习资料杭电 嵌入式 复习资料
19级学长的杭电计网实验报告,杭电计算机网络实验报告杭电计网实验报告,杭电计算机网络实验报告杭电计网实验报告,杭电计算机网络实验报告杭电计网实验报告,杭电计算机网络实验报告杭电计网实验报告,杭电计算机...
杭电acm 第1090题的.cpp文件
杭电计算机考研复试英语问题,共70余题及其自己写的简单回答,本人为杭电计算机2021年上岸考生。
杭电日历----xxyw
杭电数电实验课内题设计答案 (2).pdf杭电数电实验课内题设计答案 (2).pdf杭电数电实验课内题设计答案 (2).pdf杭电数电实验课内题设计答案 (2).pdf杭电数电实验课内题设计答案 (2).pdf杭电数电实验课内题设计答案 (2)...
杭电研究生入学易班考试题库 杭电研究生入学易班考试题库 杭电研究生入学易班考试题库
杭电计组实验9-实现R-I型指令的CPU设计实验.pdf杭电计组实验9-实现R-I型指令的CPU设计实验.pdf杭电计组实验9-实现R-I型指令的CPU设计实验.pdf杭电计组实验9-实现R-I型指令的CPU设计实验.pdf杭电计组实验9-实现R-I型...
杭电计算机组成原理MIPS汇编器模拟器实验6 (2).pdf杭电计算机组成原理MIPS汇编器模拟器实验6 (2).pdf杭电计算机组成原理MIPS汇编器模拟器实验6 (2).pdf杭电计算机组成原理MIPS汇编器模拟器实验6 (2).pdf杭电计算机...
杭电题目acm答案
主要是杭电2044到2050的题目ac代码
杭电选课器 杭电选课器 杭电
杭电oj1000题解题报告