Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Fundamentals;
- import java.util.*;
- import java.util.stream.Collectors;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int lines = Integer.parseInt(scanner.nextLine());
- List<Dragon> dragons = new ArrayList<>();
- for (int i = 1; i <= lines; i++) {
- String[] dragonData = scanner.nextLine().split(" ");
- String type = dragonData[0];
- String name = dragonData[1];
- int damage = dragonData[2].equals("null") ? 45 : Integer.parseInt(dragonData[2]);
- int health = dragonData[3].equals("null") ? 250 : Integer.parseInt(dragonData[3]);
- int armor = dragonData[4].equals("null") ? 10 : Integer.parseInt(dragonData[4]);
- Dragon newDragon = new Dragon(type, name, damage, health, armor);
- dragons.removeIf(currentDragon -> currentDragon.getType().equals(type) && currentDragon.getName().equals(name));
- dragons.add(newDragon);
- }
- Map<String, List<Dragon>> groupedDragons = dragons.stream().collect(Collectors.groupingBy(Dragon::getType,LinkedHashMap::new, Collectors.toList()));
- for (Map.Entry<String, List<Dragon>> entry : groupedDragons.entrySet()) {
- double avgDamage = entry.getValue().stream().mapToDouble(Dragon::getDamage).average().getAsDouble();
- double avgHealth = entry.getValue().stream().mapToDouble(Dragon::getHealth).average().getAsDouble();
- double avgArmor = entry.getValue().stream().mapToDouble(Dragon::getArmor).average().getAsDouble();
- System.out.printf("%s::(%.2f/%.2f/%.2f)\n", entry.getKey(), avgDamage, avgHealth, avgArmor);
- entry.getValue().sort(Comparator.comparing(Dragon::getName));
- entry.getValue().forEach(e -> System.out.printf("-%s -> damage: %d, health: %d, armor: %d\n", e.getName(), e.getDamage(), e.getHealth(), e.getArmor()));
- }
- }
- static class Dragon {
- String type;
- String name;
- int damage;
- int health;
- int armor;
- public Dragon(String type, String name, int damage, int health, int armor) {
- this.type = type;
- this.name = name;
- this.damage = damage;
- this.health = health;
- this.armor = armor;
- }
- public String getType() {
- return type;
- }
- public String getName() {
- return name;
- }
- public int getDamage() {
- return damage;
- }
- public int getHealth() {
- return health;
- }
- public int getArmor() {
- return armor;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement