Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace BattleManager
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, int> peopleHealth = new Dictionary<string, int>();
- Dictionary<string, int> peopleEnergy = new Dictionary<string, int>();
- int peopleCount = 0;
- string command = Console.ReadLine();
- while (command != "Results")
- {
- string[] splitted = command.Split(":");
- if (command.Contains("Add"))
- {
- string personName = splitted[1];
- int health = int.Parse(splitted[2]);
- int energy = int.Parse(splitted[3]);
- if (!peopleHealth.ContainsKey(personName))
- {
- peopleHealth.Add(personName, health);
- peopleEnergy.Add(personName, energy);
- peopleCount++;
- }
- else
- {
- peopleHealth[personName] += health;
- }
- }
- if (command.Contains("Attack"))
- {
- string attackerName = splitted[1];
- string defenderName = splitted[2];
- int damage = int.Parse(splitted[3]);
- if (peopleHealth.ContainsKey(attackerName) && peopleHealth.ContainsKey(defenderName))
- {
- peopleHealth[defenderName] -= damage;
- if (peopleHealth[defenderName] <= 0)
- {
- Console.WriteLine($"{defenderName} was disqualified!");
- peopleHealth.Remove(defenderName);
- peopleEnergy.Remove(defenderName);
- peopleCount--;
- }
- peopleEnergy[attackerName] -= 1;
- if (peopleEnergy[attackerName] == 0) //NB
- {
- Console.WriteLine($"{attackerName} was disqualified!");
- peopleHealth.Remove(attackerName);
- peopleEnergy.Remove(attackerName);
- peopleCount--;
- }
- }
- }
- if (command.Contains("Delete"))
- {
- string username = splitted[1];
- if (peopleHealth.ContainsKey(username))
- {
- peopleHealth.Remove(username);
- peopleEnergy.Remove(username);
- peopleCount--;
- }
- if (username == "All")
- {
- peopleHealth.Clear();
- peopleEnergy.Clear();
- peopleCount = 0;
- }
- }
- command = Console.ReadLine();
- }
- peopleHealth = peopleHealth.OrderByDescending(p => p.Value).ThenBy(p => p.Key).ToDictionary(p => p.Key, p => p.Value);
- Console.WriteLine($"People count: {peopleCount}");
- foreach (var kvp in peopleHealth)
- {
- Console.WriteLine($"{kvp.Key} - {kvp.Value} - {peopleEnergy[kvp.Key]}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement