Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class SoftUniCoffeeSupplies
- {
- static void Main()
- {
- var personCoffe = new Dictionary<string, string>();
- var coffeQuantity = new Dictionary<string, int>();
- string[] separators = Console.ReadLine().Split().ToArray();
- string[] info = new string[2];
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "end of info")
- {
- break;
- }
- if (input.Contains(separators[0]))
- {
- info = input.Split(new string[] { separators[0] }, StringSplitOptions.None);
- string person = info[0];
- string coffe = info[1];
- personCoffe[person] = coffe;
- if (!coffeQuantity.ContainsKey(coffe))
- {
- coffeQuantity[coffe] = 0;
- }
- }
- else
- {
- info = input.Split(new string[] { separators[1] }, StringSplitOptions.None);
- string coffe = info[0];
- int quantity = int.Parse(info[1]);
- if (coffeQuantity.ContainsKey(coffe))
- {
- coffeQuantity[coffe] += quantity;
- }
- else
- {
- coffeQuantity[coffe] = quantity;
- }
- }
- }
- foreach (var pair in coffeQuantity)
- {
- if (pair.Value <= 0)
- {
- Console.WriteLine("Out of {0}", pair.Key);
- }
- }
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "end of week")
- {
- break;
- }
- string[] personAndQuantity = input.Split(' ');
- string person = personAndQuantity[0];
- int quantity = int.Parse(personAndQuantity[1]);
- string coffe = personCoffe[person];
- coffeQuantity[coffe] -= quantity;
- if (coffeQuantity[coffe] <= 0)
- {
- Console.WriteLine("Out of {0}", coffe);
- }
- }
- coffeQuantity = coffeQuantity.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
- Console.WriteLine("Coffee Left:");
- foreach (var pair in coffeQuantity)
- {
- if (pair.Value > 0)
- {
- Console.WriteLine("{0} {1}", pair.Key, pair.Value);
- }
- }
- personCoffe = personCoffe.OrderBy(x => x.Value).ThenByDescending(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
- Console.WriteLine("For:");
- foreach (var pair in personCoffe)
- {
- if (coffeQuantity[pair.Value] > 0)
- {
- Console.WriteLine("{0} {1}", pair.Key, pair.Value);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement