NYOJ290,动物统计加强版HashMap
2014-11-04 12:07
232 查看
动物统计加强版
时间限制:3000 ms | 内存限制:150000 KB难度:4
描述在美丽大兴安岭原始森林中存在数量繁多的物种,在勘察员带来的各种动物资料中有未统计数量的原始动物的名单。科学家想判断这片森林中哪种动物的数量最多,但是由于数据太过庞大,科学家终于忍受不了,想请聪明如你的ACMer来帮忙。
输入第一行输入动物名字的数量N(1<= N <= 4000000),接下来的N行输入N个字符串表示动物的名字(字符串的长度不超过10,字符串全为小写字母,并且只有一组测试数据)。
输出输出这些动物中最多的动物的名字与数量,并用空格隔开(数据保证最多的动物不会出现两种以上)。
样例输入
10 boar pig sheep gazelle sheep sheep alpaca alpaca marmot mole
样例输出
sheep 3
来源[陈玉 张云聪]原创
//package NYOJ;
import java.util.HashMap;
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
HashMap<String, Integer> d = new HashMap<String, Integer>();
int n = cin.nextInt();
String smax = null;
String s = null;
int max = 1;
while (n-- > 0) {
s = cin.next();
if (d.get(s) == null) {
d.put(s, 1);
} else {
int temp = d.get(s) + 1;
d.put(s, temp);
if (max < temp) {
max = temp;
smax = s;
}
}
}
if (smax==null) System.out.println(s+" "+max);
else System.out.println(smax+" "+max);
}
}
相关文章推荐
- 动物统计加强版 nyoj290
- NYOJ 题目290 动物统计加强版(字典树)
- nyoj 290 动物统计加强版(RS哈希)
- nyoj 290 动物统计加强版 <字典树>
- nyoj 动物统计加强版 290 (字典树) 好题
- NYOJ 290 动物统计加强版
- nyoj 290 动物统计加强版 字典树
- NYOJ 题目290 动物统计加强版(字典树)
- NYOJ 290 动物统计加强版
- NYOJ 290动物统计加强版(Trie树)
- nyoj290 动物统计加强版
- nyoj-290-动物统计加强版
- NYOJ--290--动物统计加强版(字典树简单运用)
- nyoj_290动物统计加强版
- NYOJ-290 动物统计加强版 -----字典树
- nyoj290 动物统计加强版
- NYOJ 290 动物统计加强版(字典树模板题)
- NYOJ-290-动物统计加强版
- NYOJ 290 动物统计加强版(字典树)
- nyoj--290--动物统计加强版