Created
January 6, 2023 17:38
-
-
Save ram0973/27a465e87c760852e33188afeb022766 to your computer and use it in GitHub Desktop.
package com.javarush.task.task19.task1919;
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.task.task19.task1919; | |
import java.io.BufferedReader; | |
import java.io.FileReader; | |
import java.io.IOException; | |
import java.util.Comparator; | |
import java.util.Map; | |
import java.util.TreeMap; | |
import java.util.stream.Collectors; | |
/* | |
Считаем зарплаты | |
*/ | |
public class Solution { | |
public static void main(String[] args) { | |
try (BufferedReader br = new BufferedReader(new FileReader(args[0]))) { | |
br.lines() | |
.map(line -> line.split(" ")) | |
.collect(Collectors.toMap(e -> e[0], e -> Double.parseDouble(e[1]), Double::sum, TreeMap::new)) | |
.entrySet() | |
.stream() | |
.map(x -> x.getKey() + " " + x.getValue()) | |
.forEach(System.out::println); | |
} catch (IOException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Для каждого имени посчитать сумму всех его значений.
Все данные вывести в консоль, предварительно отсортировав в возрастающем порядке по имени.
Пример входного файла:
Петров 2
Сидоров 6
Иванов 1.35
Петров 3.1
Пример вывода:
Иванов 1.35
Петров 5.1
Сидоров 6.0