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