Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace ConsoleApp4
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- Dictionary<string, int> health = new Dictionary<string, int>();
- Dictionary<string, int> energy = new Dictionary<string, int>();
- while (input != "Results")
- {
- string[] tokens = input.Split(':').ToArray();
- if (tokens[0] == "Add")
- {
- if (health.ContainsKey(tokens[1]) && energy.ContainsKey(tokens[1]))
- {
- int healthPoints = int.Parse(tokens[2]);
- int energyPoints = int.Parse(tokens[3]);
- health[tokens[1]] += healthPoints;
- energy[tokens[1]] += energyPoints;
- }
- else
- {
- int healthPoints = int.Parse(tokens[2]);
- int energyPoints = int.Parse(tokens[3]);
- health.Add(tokens[1], healthPoints);
- energy.Add(tokens[1], energyPoints);
- }
- }
- else if (tokens[0] == "Attack")
- {
- if (health.ContainsKey(tokens[1]) && energy.ContainsKey(tokens[1]))
- {
- int damage = int.Parse(tokens[3]);
- health[tokens[2]] -= damage;
- energy[tokens[1]] -= 1;
- if (health[tokens[2]] <= 0)
- {
- health.Remove(tokens[2]);
- energy.Remove(tokens[2]);
- Console.WriteLine($"{tokens[2]} was disqualified!");
- }
- if (energy[tokens[1]] == 0)
- {
- health.Remove(tokens[1]);
- energy.Remove(tokens[1]);
- Console.WriteLine($"{tokens[1]} was disqualified!");
- }
- }
- }
- else if (tokens[0] == "Delete")
- {
- if (tokens[1] == "All")
- {
- health.Clear();
- energy.Clear();
- }
- else if (health.ContainsKey(tokens[1]) && energy.ContainsKey(tokens[1]))
- {
- health.Remove(tokens[1]);
- energy.Remove(tokens[1]);
- }
- }
- input = Console.ReadLine();
- }
- Console.WriteLine($"{health.Count}");
- health.OrderByDescending(x => x.Value);
- health.OrderBy(x => x.Key);
- foreach (var person in health.OrderByDescending(x => x.Value))
- {
- string currentPerson = person.Key;
- int energyValue = energy[currentPerson];
- Console.WriteLine($"{person.Key} - {person.Value} - {energyValue}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment