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 dict = new Dictionary<string, List<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 (!dict.ContainsKey(personName))
- {
- dict.Add(personName, new List<int>());
- dict[personName].Add(0);
- dict[personName].Add(energy);
- }
- dict[personName][0] += health;
- }
- else if (command == "Attack")
- {
- string attackerName = line.Split(":")[1];
- string defenderName = line.Split(":")[2];
- int damage = int.Parse(line.Split(":")[3]);
- if (dict.ContainsKey(attackerName) && dict.ContainsKey(defenderName))
- {
- dict[defenderName][0] -= damage;
- dict[attackerName][1] -= 1;
- if (dict[defenderName][0] <= 0)
- {
- Console.WriteLine($"{defenderName} was disqualified!");
- dict.Remove(defenderName);
- }
- if (dict[attackerName][1] <= 0)
- {
- Console.WriteLine($"{attackerName} was disqualified!");
- dict.Remove(attackerName);
- }
- }
- }
- else if (command == "Delete")
- {
- string username = line.Split(":")[1];
- if (username == "All")
- {
- dict.Clear();
- }
- else if(dict.ContainsKey(username))
- {
- dict.Remove(username);
- }
- }
- }
- Console.WriteLine($"People count: {dict.Keys.Count}");
- foreach (var item in dict.OrderByDescending(x => x.Value[0]).ThenBy(x => x.Key))
- {
- Console.WriteLine($"{item.Key} - {item.Value[0]} - {item.Value[1]}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement