Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _6._2_Solution
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> input = Console.ReadLine().Split(":").ToList();
- string command = input[0];
- Dictionary<string, int> food = new Dictionary<string, int>();
- Dictionary<string, List<string>> area = new Dictionary<string, List<string>>();
- while (command != "Last Info")
- {
- string animal = input[1];
- string currentArea = input[3];
- if (command == "Add")
- {
- int daylyFood = int.Parse(input[2]);
- if (!food.ContainsKey(animal))
- {
- food[animal] = 0;
- }
- food[animal] += daylyFood;
- if (!area.ContainsKey(currentArea))
- {
- area[currentArea] = new List<string>();
- }
- if (!area[currentArea].Contains(animal))
- {
- area[currentArea].Add(animal);
- }
- }
- else if (command == "Feed")
- {
- int currentFood = int.Parse(input[2]);
- if (food.ContainsKey(animal))
- {
- food[animal] -= currentFood;
- if (food[animal] <= 0)
- {
- Console.WriteLine($"{animal} was successfully fed");
- food.Remove(animal);
- area[currentArea].Remove(animal);
- }
- }
- }
- input = Console.ReadLine().Split(":").ToList();
- command = input[0];
- }
- food = food.OrderByDescending(x => x.Value).ThenBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
- area = area.Where(x => x.Value.Count != 0).OrderByDescending(x => x.Value.Count).ToDictionary(x => x.Key, y => y.Value);
- Console.WriteLine("Animals:");
- foreach (var item in food)
- {
- Console.WriteLine(item.Key + " -> " + item.Value + "g");
- }
- Console.WriteLine("Areas with hungry animals:");
- foreach (var item in area)
- {
- Console.WriteLine($"{item.Key} : {item.Value.Count}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement