Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.image.AreaAveragingScaleFilter;
- import java.lang.reflect.Array;
- import java.util.Map;
- import java.util.Scanner;
- import java.util.TreeMap;
- public class BattleManager {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- Map<String, int[]> people = new TreeMap<>();
- String[] command = scanner.nextLine().split(":");
- while (!command[0].equals("Results")) {
- switch (command[0]) {
- case "Add":
- String name = command[1];
- int health = Integer.parseInt(command[2]);
- int energy = Integer.parseInt(command[3]);
- int[] healthEnergy = new int[2];
- if (!people.containsKey(name)) {
- healthEnergy[0] = health;
- healthEnergy[1] = energy;
- people.put(name, healthEnergy);
- } else {
- healthEnergy[0] = people.get(name)[0] + health;
- people.put(name, healthEnergy);
- }
- break;
- case "Attack":
- String attackerName = command[1];
- String defenderName = command[2];
- int damage = Integer.parseInt(command[3]);
- if (people.containsKey(attackerName) && people.containsKey(defenderName)) {
- people.get(defenderName)[0] = people.get(defenderName)[0] - damage;
- if (people.get(defenderName)[0] <= 0) {
- System.out.println(defenderName + " was disqualified!");
- people.remove(defenderName);
- }
- people.get(attackerName)[1] = people.get(attackerName)[1] - 1;
- if (people.get(attackerName)[1] <= 0) {
- System.out.println(attackerName + " was disqualified!");
- people.remove(attackerName);
- }
- }
- break;
- case "Delete":
- String username = command[1];
- if (username.equals("All")) {
- people = new TreeMap<>();
- } else people.remove(username);
- break;
- }
- command = scanner.nextLine().split(":");
- }
- if (people.size() > 0) {
- System.out.println("People count: " + people.size());
- }
- people.entrySet()
- .stream()
- .sorted((a, b) -> {
- int compare = b.getValue()[0] - a.getValue()[0];
- if (compare == 0) {
- return a.getKey().compareTo(b.getKey());
- } else {
- return compare;
- }
- }).forEach((e) -> System.out.printf("%s - %d - %d%n", e.getKey(), e.getValue()[0], e.getValue()[1]));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement