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