Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.util.concurrent.atomic.AtomicInteger;
- public class InternationalSoftUniada2 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- LinkedHashMap<String, List<String>> countryAndName = new LinkedHashMap<>();
- HashMap<String, Integer> nameAndPoints = new HashMap<>();
- String input = scanner.nextLine();
- while (!input.equals("END")) {
- String[] tokens = input.split(" ->");
- String country = tokens[0];
- String name = tokens[1];
- if (!countryAndName.containsKey(country)) {
- countryAndName.put(country, new ArrayList<>());
- countryAndName.get(country).add(name);
- }
- if (!nameAndPoints.containsKey(name)) {
- int point = Integer.parseInt(tokens[2].trim());
- nameAndPoints.put(name, point);
- } else {
- int point = Integer.parseInt(tokens[2].trim());
- int currentPoint = nameAndPoints.get(name) + point;
- nameAndPoints.put(name, currentPoint);
- }
- input = scanner.nextLine();
- }
- countryAndName.entrySet().forEach(entry -> System.out.printf("%s: %d%n", entry.getKey()
- ,nameAndPoints.entrySet().stream().mapToInt(e -> e.getValue()).sum()));
- nameAndPoints.entrySet().stream()
- .sorted((e1, e2) -> e2.getValue().compareTo(e1.getValue()))
- .forEach(entry -> System.out.printf(" -- %s -> %d%n", entry.getKey(), entry.getValue()));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement