Advertisement
knoteva

Untitled

Aug 5th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _03._Program
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var healthD = new Dictionary<string, int>();
  12.             var energyD = new Dictionary<string, int>();
  13.             var line = string.Empty;
  14.  
  15.             while ((line = Console.ReadLine()) != "Results")
  16.             {
  17.                 string command = line.Split(":")[0];
  18.  
  19.                 if (command == "Add")
  20.                 {
  21.                     string personName = line.Split(":")[1];
  22.                     int health = int.Parse(line.Split(":")[2]);
  23.                     int energy = int.Parse(line.Split(":")[3]);
  24.                     if (!healthD.ContainsKey(personName))
  25.                     {
  26.                         healthD.Add(personName, 0);
  27.                         energyD.Add(personName, energy);
  28.                     }
  29.  
  30.                     healthD[personName] += health;
  31.                 }
  32.                 else if (command == "Attack")
  33.                 {
  34.                     string attackerName = line.Split(":")[1];
  35.                     string defenderName = line.Split(":")[2];
  36.                     int damage = int.Parse(line.Split(":")[3]);
  37.  
  38.                     if (healthD.ContainsKey(attackerName) && healthD.ContainsKey(defenderName))
  39.                     {
  40.                         healthD[defenderName] -= damage;
  41.                         energyD[attackerName] -= 1;
  42.                         if (healthD[defenderName] <= 0)
  43.                         {
  44.                             Console.WriteLine($"{defenderName} was disqualified!");
  45.                             healthD.Remove(defenderName);
  46.                             energyD.Remove(defenderName);
  47.                         }
  48.  
  49.                         if (energyD[attackerName] <= 0)
  50.                         {
  51.                             Console.WriteLine($"{attackerName} was disqualified!");
  52.                             healthD.Remove(attackerName);
  53.                             energyD.Remove(attackerName);
  54.                         }
  55.                     }
  56.                 }
  57.                 else if (command == "Delete")
  58.                 {
  59.                     string username = line.Split(":")[1];
  60.  
  61.                     if (username == "All")
  62.                     {
  63.                         healthD.Clear();
  64.                         energyD.Clear();
  65.                     }
  66.                     else if (healthD.ContainsKey(username))
  67.                     {
  68.                         healthD.Remove(username);
  69.                         energyD.Remove(username);
  70.                     }
  71.                 }
  72.             }
  73.  
  74.             Console.WriteLine($"People count: {healthD.Keys.Count}");
  75.  
  76.             foreach (var item in healthD.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  77.             {
  78.                 var energy = energyD[item.Key];
  79.                 Console.WriteLine($"{item.Key} - {item.Value} - {energy}");
  80.             }
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement