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