Advertisement
Guest User

Untitled

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