.
package com.javarush.task.task19.task1920;
/*
Самый богатый
*/
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(args[0]));
Map<String, Double> info = new HashMap<>();
List<String> strings = new LinkedList<>();
List<Double> doubles = new LinkedList<>();
for (; ; ) {
try {
String line = reader.readLine();
if (line == null) {
break;
}
String[] str = line.split(" ");
String el1 = str[0];
double el2 = Double.valueOf(str[1]);
strings.add(el1);
doubles.add(el2);
} catch (ArrayIndexOutOfBoundsException arindex) {
}
}
reader.close();
HashMap<String, Double> map = new HashMap<>();
for (int i = 0; i < strings.size(); i++) {
for (int j = 0; j < strings.size(); j++) {
if (strings.get(i).equals(strings.get(j)) && i != j) {
doubles.set(i, doubles.get(i) + doubles.get(j));
strings.remove(j);
doubles.remove(j);
}
}
}
ArrayList<String> copyStr = new ArrayList<>(strings);
ArrayList<Double> copyDub = new ArrayList<>(doubles);
System.out.println(copyStr);
System.out.println(copyDub);
Collections.sort(copyDub);
Collections.sort(copyStr);
for (int i = 0; i < copyStr.size(); i++) {
if(doubles.get(i).equals(copyDub.get(copyDub.size()-1) )){
System.out.println(strings.get(i) );
}
}
}
}