Advertisement
Guest User

Untitled

a guest
Jun 11th, 2016
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.43 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. class Program
  6. {
  7.     static void Main()
  8.     {
  9.         string[] delimeters = Console.ReadLine().Split();
  10.  
  11.         Dictionary<string, long> coffeeQuantity = new Dictionary<string, long>();
  12.         Dictionary<string, string> personalPreference = new Dictionary<string, string>();
  13.  
  14.         string input = Console.ReadLine();
  15.         while(input!="end of info")
  16.         {
  17.             string[] data;
  18.             if (input.Contains(delimeters[0]))
  19.             {
  20.                 data = input.Split(new string[] { delimeters[0] }, StringSplitOptions.RemoveEmptyEntries);
  21.                 personalPreference[data[0]] = data[1];
  22.                 if (!coffeeQuantity.ContainsKey(data[1]))
  23.                     coffeeQuantity[data[1]] = 0;
  24.             }
  25.             else
  26.             {
  27.                 data = input.Split(new string[] { delimeters[1] }, StringSplitOptions.RemoveEmptyEntries);
  28.                 if (!coffeeQuantity.ContainsKey(data[0]))
  29.                     coffeeQuantity[data[0]] = 0;
  30.                 coffeeQuantity[data[0]] += long.Parse(data[1]);
  31.             }
  32.  
  33.             input = Console.ReadLine();
  34.         }
  35.  
  36.         string noneLeft = string.Empty;
  37.         foreach (var coffee in coffeeQuantity)
  38.             if (coffee.Value <= 0)
  39.                 noneLeft += $"Out of {coffee.Key}\n";
  40.  
  41.         input = Console.ReadLine();
  42.         while (input!="end of week")
  43.         {
  44.             string[] data = input.Split();
  45.             coffeeQuantity[personalPreference[data[0]]] -= long.Parse(data[1]);
  46.             if (coffeeQuantity[personalPreference[data[0]]]<=0)
  47.                 noneLeft += $"Out of {personalPreference[data[0]]}\n";
  48.             input = Console.ReadLine();
  49.         }
  50.         Console.Write(noneLeft);
  51.         Console.WriteLine("Coffee Left:");
  52.         coffeeQuantity = coffeeQuantity.OrderByDescending(x => x.Value).ToDictionary(x=>x.Key, y=>y.Value);
  53.         foreach (var coffee in coffeeQuantity)
  54.             if (coffee.Value>0)
  55.                 Console.WriteLine($"{coffee.Key} {coffee.Value}");
  56.         personalPreference = personalPreference.OrderBy(x => x.Value).ThenByDescending(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
  57.         Console.WriteLine("For:");
  58.         foreach (var person in personalPreference)
  59.             if (coffeeQuantity[person.Value]>0)
  60.                 Console.WriteLine($"{person.Key} {person.Value}");
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement