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