fbinnzhivko

Untitled

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