Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Security.Cryptography.X509Certificates;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace _04.SoftUni_Coffee_Supplies
  9. {
  10.     class Program
  11.     {
  12.         public class Coffe
  13.         {
  14.             public string CofeeType { get; set; }
  15.             public int  CoffeMaxCount { get; set; }
  16.             public List<string> PeopleDrinkingThisCoffe { get; set; }
  17.             public List<int> DrinkingCoffesForWeek { get; set; }
  18.             public int LeftCoffe { get; set; }
  19.         }
  20.         static void Main(string[] args)
  21.         {
  22.             List<Coffe> coffeList = new List<Coffe>();
  23.  
  24.             string[] inputKeys = Console.ReadLine().Split();
  25.             string firstKey = inputKeys[0].Trim();
  26.             string secondKey = inputKeys[1].Trim();
  27.  
  28.             while (true)
  29.             {
  30.                 var createCoffe = new Coffe();
  31.                 string inputCoffe = Console.ReadLine();
  32.                 if (inputCoffe == "end of info")
  33.                 {
  34.                     break;
  35.                 }
  36.                 if (inputCoffe.Contains(firstKey))
  37.                 {
  38.                     string[] tokens =
  39.                         inputCoffe.Split(new string[] {$"{firstKey}"}, StringSplitOptions.RemoveEmptyEntries);
  40.                     string peopleDrinkingThisCoffe = tokens[0].Trim();
  41.                     string coffeType = tokens[1].Trim();
  42.  
  43.                     foreach (var coffe in coffeList)
  44.                     {
  45.                         if (coffe.CofeeType.Contains(coffeType))
  46.                         {
  47.                             coffe.PeopleDrinkingThisCoffe.Add(peopleDrinkingThisCoffe);
  48.                             break;
  49.                         }
  50.                     }
  51.                     var result = coffeList.FindIndex(a => a.CofeeType == coffeType);
  52.                     if (result == -1)
  53.                     {
  54.                         createCoffe.CofeeType = coffeType;
  55.                         createCoffe.PeopleDrinkingThisCoffe = new List<string>();
  56.                         createCoffe.DrinkingCoffesForWeek = new List<int>();
  57.                         createCoffe.PeopleDrinkingThisCoffe.Add(peopleDrinkingThisCoffe);
  58.  
  59.                         coffeList.Add(createCoffe);
  60.                     }
  61.                 }
  62.                 else
  63.                 {
  64.                     string[] tokens = inputCoffe.Split(new string[] {$"{secondKey}"},
  65.                         StringSplitOptions.RemoveEmptyEntries);
  66.  
  67.                     string coffeType = tokens[0].Trim();
  68.                     int coffeMaxCount = int.Parse(tokens[1].Trim());
  69.  
  70.                     int indexOfCurrentCoffe = coffeList.FindIndex(a => a.CofeeType == coffeType);
  71.  
  72.                     coffeList[indexOfCurrentCoffe].CoffeMaxCount += coffeMaxCount;
  73.                     coffeList[indexOfCurrentCoffe].LeftCoffe += coffeMaxCount;
  74.                 }              
  75.             }
  76.             foreach (var zeroCoffe in coffeList)
  77.             {
  78.                 if (zeroCoffe.LeftCoffe == 0)
  79.                 {
  80.                     Console.WriteLine($"Out of {zeroCoffe.CofeeType}");
  81.                 }
  82.             }
  83.  
  84.             while (true)
  85.             {
  86.                 string drinkingCoffeThisWeek = Console.ReadLine();
  87.                 if (drinkingCoffeThisWeek == "end of week")
  88.                 {
  89.                     break;
  90.                 }
  91.  
  92.                 string[] weeksCoffes = drinkingCoffeThisWeek.Split();
  93.                 string peopleDrinkingCoffe = weeksCoffes[0].Trim();
  94.                 int coffeCount = int.Parse(weeksCoffes[1].Trim());
  95.              
  96.                 foreach (var item in coffeList)
  97.                 {                
  98.                     if (item.PeopleDrinkingThisCoffe.Contains(peopleDrinkingCoffe))
  99.                     {                      
  100.                         int indexOfCurrentCoffe =
  101.                             item.PeopleDrinkingThisCoffe.FindIndex(e => e.Equals(peopleDrinkingCoffe));
  102.  
  103.                         if (indexOfCurrentCoffe >= 0)
  104.                         {
  105.                             item.DrinkingCoffesForWeek.Add(coffeCount);
  106.                             item.LeftCoffe -= coffeCount;                                                
  107.                             if (item.LeftCoffe <= 0)
  108.                             {
  109.                                 Console.WriteLine($"Out of {item.CofeeType}");
  110.                             }
  111.                             break;
  112.                         }
  113.                     }                
  114.                 }
  115.             }
  116.             Console.WriteLine("Coffee Left:");
  117.             foreach (var coffeType in coffeList.OrderByDescending(a => a.LeftCoffe))
  118.             {
  119.                 int totalDrinkingCoffeForType = coffeType.DrinkingCoffesForWeek.Sum();
  120.  
  121.                 if (coffeType.CoffeMaxCount > totalDrinkingCoffeForType)
  122.                 {
  123.                     int totalLeftCoffeForType = coffeType.CoffeMaxCount - totalDrinkingCoffeForType;
  124.                     coffeType.LeftCoffe = totalLeftCoffeForType;                  
  125.                     Console.WriteLine($"{coffeType.CofeeType} {totalLeftCoffeForType}");
  126.                 }
  127.             }
  128.             Console.WriteLine("For:");
  129.             foreach (var item in coffeList.OrderBy(a => a.CofeeType))
  130.             {
  131.                 foreach (var peope in item.PeopleDrinkingThisCoffe.OrderByDescending(a => a))
  132.                 {
  133.                     if (item.LeftCoffe > 0)
  134.                     {
  135.                         Console.WriteLine($"{peope} {item.CofeeType}");
  136.                     }                  
  137.                 }
  138.             }
  139.         }
  140.     }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement