Advertisement
fbinnzhivko

02.01 SoftUniWaterSupplies

Jun 10th, 2016
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. class Program
  5. {
  6.     static void Main()
  7.     {
  8.         decimal totalWater = decimal.Parse(Console.ReadLine());
  9.         decimal[] bottlesArray = Console.ReadLine().Split(' ').Select(decimal.Parse).ToArray();
  10.         decimal bottlesCapacity = decimal.Parse(Console.ReadLine());
  11.  
  12.         decimal consumedWater = 0;
  13.         decimal bottlesFilled = 0;
  14.        
  15.         decimal allBottles = bottlesArray.Length;
  16.  
  17.         List<decimal> indexes = new List<decimal>();
  18.  
  19.         if (totalWater % 2 == 0)
  20.         {
  21.             for (int i = 0; i < allBottles; i++)
  22.             {
  23.                 consumedWater += bottlesCapacity - bottlesArray[i];
  24.                 if (consumedWater <= totalWater)
  25.                     bottlesFilled++;
  26.                 else
  27.                     indexes.Add(i);
  28.             }
  29.         }
  30.         else
  31.         {
  32.             for (decimal i = allBottles - 1; i >= 0; i--)
  33.             {
  34.                 consumedWater += bottlesCapacity - bottlesArray[(int)i];
  35.                 if (consumedWater <= totalWater)
  36.                     bottlesFilled++;
  37.                 else
  38.                     indexes.Add(i);
  39.             }
  40.         }
  41.         if (consumedWater <= totalWater)
  42.         {
  43.             Console.WriteLine("Enough water!");
  44.             Console.WriteLine("Water left: {0}l.", totalWater - consumedWater);
  45.         }
  46.         if (consumedWater > totalWater)
  47.         {
  48.             Console.WriteLine("We need more water!");
  49.             Console.WriteLine("Bottles left: {0}", allBottles - bottlesFilled);
  50.             Console.WriteLine("With indexes: {0}", string.Join(", ", indexes));
  51.             Console.WriteLine("We need {0} more liters!", consumedWater - totalWater);
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement