Advertisement
MZlatev

Untitled

Dec 2nd, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _6._2_Solution
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<string> input = Console.ReadLine().Split(":").ToList();
  12. string command = input[0];
  13.  
  14. Dictionary<string, int> food = new Dictionary<string, int>();
  15. Dictionary<string, List<string>> area = new Dictionary<string, List<string>>();
  16.  
  17. while (command != "Last Info")
  18. {
  19. string animal = input[1];
  20. string currentArea = input[3];
  21.  
  22. if (command == "Add")
  23. {
  24. int daylyFood = int.Parse(input[2]);
  25. if (!food.ContainsKey(animal))
  26. {
  27. food[animal] = 0;
  28.  
  29. }
  30. food[animal] += daylyFood;
  31.  
  32. if (!area.ContainsKey(currentArea))
  33. {
  34. area[currentArea] = new List<string>();
  35. }
  36.  
  37. if (!area[currentArea].Contains(animal))
  38. {
  39. area[currentArea].Add(animal);
  40. }
  41.  
  42. }
  43. else if (command == "Feed")
  44. {
  45. int currentFood = int.Parse(input[2]);
  46.  
  47. if (food.ContainsKey(animal))
  48. {
  49. food[animal] -= currentFood;
  50.  
  51. if (food[animal] <= 0)
  52. {
  53. Console.WriteLine($"{animal} was successfully fed");
  54. food.Remove(animal);
  55. area[currentArea].Remove(animal);
  56. }
  57.  
  58. }
  59. }
  60.  
  61.  
  62. input = Console.ReadLine().Split(":").ToList();
  63. command = input[0];
  64. }
  65.  
  66. food = food.OrderByDescending(x => x.Value).ThenBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
  67. area = area.Where(x => x.Value.Count != 0).OrderByDescending(x => x.Value.Count).ToDictionary(x => x.Key, y => y.Value);
  68.  
  69. Console.WriteLine("Animals:");
  70. foreach (var item in food)
  71. {
  72. Console.WriteLine(item.Key + " -> " + item.Value + "g");
  73. }
  74. Console.WriteLine("Areas with hungry animals:");
  75. foreach (var item in area)
  76. {
  77. Console.WriteLine($"{item.Key} : {item.Value.Count}");
  78. }
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement