направьте на путь истинный)
package com.javarush.task.task19.task1920;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.*;
/*
Ñàìûé áîãàòûé
*/
public class Solution {
public static class DoubleComparator implements Comparator<Double>{
@Override
public int compare(Double t, Double t1) {
return (int) Math.max(t, t1);
}
}
public static void main(String[] args) throws IOException {
Map<String, Double> map = new TreeMap<>();
SortedSet<Map.Entry<String, Double>> sortedSet = new TreeSet<Map.Entry<String, Double>>(new Comparator<Map.Entry<String, Double>>() {
@Override
public int compare(Map.Entry<String, Double> e1, Map.Entry<String, Double> e2) {
return e2.getValue().compareTo(e1.getValue());
}
});
Map<Double, String> sortedMap = new TreeMap<>();
List<String> listKeys = new ArrayList<>();
List<Double> listValues = new ArrayList<>();
FileReader fileReader = new FileReader(args[0]);
BufferedReader reader = new BufferedReader(fileReader);
String[] line = new String[2];
String s;
line[0] = " ";
double d = 0;
double d1 = 0;
double scale = Math.pow(10, 0);
while (reader.ready()) {
line = reader.readLine().split(" ");
if (line[0].equals("")) break;
if (map.containsKey(line[0])) {
d1 = map.get(line[0]) + Double.parseDouble(line[1]);
d = Math.ceil(d1 * scale) / scale;
map.put(line[0], d1);
} else map.put(line[0], Double.parseDouble(line[1]));
}
reader.close();
fileReader.close();
sortedSet.addAll(map.entrySet());
map.clear();
DecimalFormat decimalFormat = new DecimalFormat("#,#");
while (true) {
s = sortedSet.first().toString();
line = s.split("=");
d = Double.parseDouble(decimalFormat.format(Double.parseDouble(line[1])));
if (map.isEmpty()) {
map.put(line[0], d);
}else if (map.containsValue(d)){
map.put(line[0], d);
}else break;
sortedSet.remove(sortedSet.first());
}
for (Map.Entry<String, Double> pair : map.entrySet()){
System.out.print(pair.getKey() + " ");
}
}
}