SHARE
TWEET

CupsAndBottles

a guest May 22nd, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace CupsAndBottles
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int[] cupsCapacity = Console.ReadLine()
  12.                 .Split()
  13.                 .Select(int.Parse)
  14.                 .ToArray();
  15.             int[] bottlesWithWater = Console.ReadLine()
  16.                 .Split()
  17.                 .Select(int.Parse)
  18.                 .ToArray();
  19.  
  20.  
  21.             var stackOfBottles = new Stack<int>(bottlesWithWater);
  22.             var queueOfCups = new Queue<int>(cupsCapacity);
  23.  
  24.             int totalWastedWater = 0;
  25.  
  26.             while (true)
  27.             {
  28.                 if (stackOfBottles.Peek() >= queueOfCups.Peek())
  29.                 {
  30.                     int currentBottle = stackOfBottles.Pop();
  31.                     int currentCup = queueOfCups.Dequeue();
  32.  
  33.                     int wastedWater = currentBottle - currentCup;
  34.                     totalWastedWater += wastedWater;
  35.                     stackOfBottles.Pop();
  36.                     queueOfCups.Dequeue();
  37.                 }
  38.                 else
  39.                 {
  40.                     //??? TO DO
  41.                 }
  42.  
  43.                 if (stackOfBottles.Count == 0)
  44.                 {
  45.                     Console.WriteLine("Cups: " + string.Join(" ", queueOfCups));
  46.                     break;
  47.                 }
  48.                 if (queueOfCups.Count == 0)
  49.                 {
  50.                     Console.WriteLine("Bottles: " + string.Join(" ", stackOfBottles));
  51.                     break;
  52.                 }
  53.             }
  54.             Console.WriteLine($"Wasted litters of water: {totalWastedWater}");
  55.         }
  56.     }
  57. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top