# 题目信息

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 194179 Accepted Submission(s): 78028

# 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

1
2
3
4
5
6
7
8
9
10
11
5
green
red
blue
red
red
3
pink
orange
pink
0

# Sample Output

1
2
red
pink

# 题解

# Java 语言解法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

class Demo {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int i = sc.nextInt();
if (i == 0) {
break;
}
HashMap<String, Integer> map = new HashMap<>();
String key = "";
int maxCount = 0;
while (i-- > 0) {
String s = sc.nextLine();
int value = map.getOrDefault(s, 0) + 1;
if (maxCount < value) {
maxCount = value;
key = s;
}
map.put(s, value);
}

System.out.println(key);
}
}
}

# Be Careful

to easy. nothing… but High-level language YYDS.

# 链接

# 最后

希望与你一起遇见更好的自己

期望与你一起遇见更好的自己

更新于 阅读次数

请我喝[咖啡]~( ̄▽ ̄)~*

方小白 微信支付

微信支付

方小白 支付宝

支付宝

方小白 numberpay

numberpay