Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _02.FeedYheAnimal
- {
- 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, string> area = new Dictionary<string, string>();
- //Dictionary<string, int> hungry = new Dictionary<string, int>();
- int counter = 0;
- 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;
- area[animal] = "";
- }
- food[animal] += daylyFood;
- area[animal] = currentArea;
- }
- 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.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.OrderByDescending(x => x.Value).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.Value + " : " + area.Count);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment