Advertisement
ralichka

Untitled

Dec 2nd, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.56 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _02.FeedYheAnimal
  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.             //Dictionary<string, int> hungry = new Dictionary<string, int>();
  17.  
  18.            
  19.             while (command != "Last Info")
  20.             {
  21.                 string animal = input[1];
  22.                 string currentArea = input[3];
  23.  
  24.                 if (command == "Add")
  25.                 {
  26.                     int daylyFood = int.Parse(input[2]);
  27.                     if (!food.ContainsKey(animal))
  28.                     {
  29.                         food[animal] = 0;
  30.                         area[currentArea] = new List<string>();
  31.                        
  32.                     }
  33.                     food[animal] += daylyFood;
  34.                     area[currentArea].Add(animal);
  35.                 }
  36.                 else if (command == "Feed")
  37.                 {
  38.                     int currentFood = int.Parse(input[2]);
  39.  
  40.                     if (food.ContainsKey(animal))
  41.                     {
  42.                         food[animal] -= currentFood;
  43.                        
  44.  
  45.                     }
  46.                 }
  47.                 //ето товеа мисля е на погрешното място
  48.                 if (food[animal] <= 0)
  49.                 {
  50.                     Console.WriteLine($"{animal} was successfully fed");
  51.                     food.Remove(animal);
  52.                     area[currentArea].Remove(animal);                  
  53.                 }
  54.  
  55.  
  56.                 input = Console.ReadLine().Split(":").ToList();
  57.                 command = input[0];
  58.             }
  59.  
  60.             food = food.OrderByDescending(x => x.Value).ThenBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
  61.             area = area.OrderByDescending(x => x.Value.Count).ToDictionary(x => x.Key, y => y.Value);
  62.  
  63.             Console.WriteLine("Animals:");
  64.             foreach (var item in food)
  65.             {
  66.                 Console.WriteLine(item.Key + " -> " + item.Value + "g");
  67.             }
  68.             Console.WriteLine("Areas with hungry animals:");
  69.             foreach (var item in area)
  70.             {
  71.                 Console.WriteLine($"{item.Key}  :  {item.Value.Count}");
  72.             }
  73.  
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement