Advertisement
fbinnzhivko

04.01 SoftUniCofeeSupplies

Jun 11th, 2016
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.95 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. class SoftUniCoffeeSupplies
  5. {
  6.     static void Main()
  7.     {
  8.         var personCoffe = new Dictionary<string, string>();
  9.         var coffeQuantity = new Dictionary<string, int>();
  10.  
  11.         string[] separators = Console.ReadLine().Split().ToArray();
  12.         string[] info = new string[2];
  13.  
  14.         while (true)
  15.         {
  16.             string input = Console.ReadLine();
  17.             if (input == "end of info")
  18.             {
  19.                 break;
  20.             }
  21.  
  22.             if (input.Contains(separators[0]))
  23.             {
  24.                 info = input.Split(new string[] { separators[0] }, StringSplitOptions.None);
  25.                 string person = info[0];
  26.                 string coffe = info[1];
  27.                 personCoffe[person] = coffe;
  28.                 if (!coffeQuantity.ContainsKey(coffe))
  29.                 {
  30.                     coffeQuantity[coffe] = 0;
  31.                 }
  32.             }
  33.             else
  34.             {
  35.                 info = input.Split(new string[] { separators[1] }, StringSplitOptions.None);
  36.                 string coffe = info[0];
  37.                 int quantity = int.Parse(info[1]);
  38.                 if (coffeQuantity.ContainsKey(coffe))
  39.                 {
  40.                     coffeQuantity[coffe] += quantity;
  41.                 }
  42.                 else
  43.                 {
  44.                     coffeQuantity[coffe] = quantity;
  45.                 }
  46.             }
  47.         }
  48.         foreach (var pair in coffeQuantity)
  49.         {
  50.             if (pair.Value <= 0)
  51.             {
  52.                 Console.WriteLine("Out of {0}", pair.Key);
  53.             }
  54.         }
  55.         while (true)
  56.         {
  57.             string input = Console.ReadLine();
  58.             if (input == "end of week")
  59.             {
  60.                 break;
  61.             }
  62.             string[] personAndQuantity = input.Split(' ');
  63.             string person = personAndQuantity[0];
  64.             int quantity = int.Parse(personAndQuantity[1]);
  65.  
  66.             string coffe = personCoffe[person];
  67.             coffeQuantity[coffe] -= quantity;
  68.             if (coffeQuantity[coffe] <= 0)
  69.             {
  70.                 Console.WriteLine("Out of {0}", coffe);
  71.             }
  72.         }
  73.  
  74.         coffeQuantity = coffeQuantity.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
  75.  
  76.         Console.WriteLine("Coffee Left:");
  77.         foreach (var pair in coffeQuantity)
  78.         {
  79.             if (pair.Value > 0)
  80.             {
  81.                 Console.WriteLine("{0} {1}", pair.Key, pair.Value);
  82.             }
  83.         }
  84.  
  85.         personCoffe = personCoffe.OrderBy(x => x.Value).ThenByDescending(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
  86.  
  87.         Console.WriteLine("For:");
  88.         foreach (var pair in personCoffe)
  89.         {
  90.             if (coffeQuantity[pair.Value] > 0)
  91.             {
  92.                 Console.WriteLine("{0} {1}", pair.Key, pair.Value);
  93.             }
  94.         }
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement