在intelij Idea验证没有问题,怎么通过不了呢?
package zh.codegym.task.task19.task1920;
import java.io.*;
import java.util.*;
/*
首富
*/
public class Solution {
public static void main(String[] args) {
FileReader fr = null;
BufferedReader fre = null;
HashMap<String, Double> hamap = new HashMap<String, Double>();
try {
fr = new FileReader(args[0]);
fre = new BufferedReader(fr);
String str = null;
while((str = fre.readLine()) != null) {
String[] arrstr = str.split(" ");
if (hamap.containsKey(arrstr[0]))
{
double tmp = hamap.get(arrstr[0]) + Double.parseDouble(arrstr[1]);
hamap.put(arrstr[0], tmp);
}
else
{
hamap.put(arrstr[0], Double.parseDouble(arrstr[1]));
}
}
List<Map.Entry<String,Double>> list =
new ArrayList<Map.Entry<String,Double>>(hamap.entrySet());
//然后通过比较器来实现排序
Collections.sort(list,new Comparator<Map.Entry<String,Double>>() {
//降序排序
public int compare(Map.Entry<String, Double> o1,
Map.Entry<String, Double> o2) {
return o2.getValue().compareTo(o1.getValue());
}
});
double dtmp = list.get(0).getValue();//找到最大值的成员,排序后是第一个成员
TreeMap<String, Double> trmap = new TreeMap<String, Double>();
for (Map.Entry<String, Double> entry : hamap.entrySet()) {
//如果有多个等于最大值的成员,都加入到treemap
if (dtmp == entry.getValue()) {
trmap.put(entry.getKey(), entry.getValue());
}
}
List<Map.Entry<String,Double>> list2 =
new ArrayList<Map.Entry<String,Double>>(trmap.entrySet());
//然后通过比较器来实现排序
Collections.sort(list2,new Comparator<Map.Entry<String,Double>>() {
//按字母表升序排序
public int compare(Map.Entry<String, Double> o1,
Map.Entry<String, Double> o2) {
return o2.getKey().substring(0,1).compareTo(o1.getKey().substring(0,1));
}
});
for (Map.Entry<String, Double> entry : list2) {
System.out.println(entry.getKey());
}
}
catch (IOException e){
}
finally{
try{
fre.close();
fr.close();
}
catch(IOException e){
}
}
}
}