Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _5._1_FeedTheAnimalsWithInt
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, int> animalsAndDailyLimit = new Dictionary<string, int>();
- Dictionary<string, int> areaAndUnfedAnimals = new Dictionary<string, int>();
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "Last Info")
- {
- break;
- }
- string[] splitedInput = input.Split(":");
- string command = splitedInput[0];
- string animalName = splitedInput[1];
- string area = splitedInput[3];
- if (command == "Add")
- {
- int dailyFoodLimit = int.Parse(splitedInput[2]);
- if (!animalsAndDailyLimit.ContainsKey(animalName))
- {
- animalsAndDailyLimit.Add(animalName, dailyFoodLimit);
- if (!areaAndUnfedAnimals.ContainsKey(area))
- {
- areaAndUnfedAnimals.Add(area, 0);
- }
- areaAndUnfedAnimals[area]++;
- }
- else
- {
- animalsAndDailyLimit[animalName] += dailyFoodLimit;
- }
- }
- else
- {
- int food = int.Parse(splitedInput[2]);
- if (animalsAndDailyLimit.ContainsKey(animalName))
- {
- animalsAndDailyLimit[animalName] -= food;
- if (animalsAndDailyLimit[animalName] <= 0)
- {
- Console.WriteLine($"{animalName} was successfully fed");
- animalsAndDailyLimit.Remove(animalName);
- areaAndUnfedAnimals[area]--;
- }
- }
- }
- }
- Console.WriteLine("Animals:");
- foreach (var kvp in animalsAndDailyLimit
- .OrderByDescending(x => x.Value)
- .ThenBy(x => x.Key))
- {
- Console.WriteLine($"{kvp.Key} -> {kvp.Value}g");
- }
- Console.WriteLine("Areas with hungry animals:");
- foreach (var kvp in areaAndUnfedAnimals
- .OrderByDescending(x => x.Value)
- .Where(x => x.Value != 0))
- {
- Console.WriteLine($"{kvp.Key} : {kvp.Value}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement