Advertisement
fbinnzhivko

Untitled

Jun 10th, 2016
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.02 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. class Program
  4. {
  5.     static void Main()
  6.     {
  7.         double totalWater = double.Parse(Console.ReadLine());
  8.         double[] bottlesIncome = Console.ReadLine().Split().Select(double.Parse).ToArray();
  9.         double bootleCapacity = double.Parse(Console.ReadLine());
  10.  
  11.         double totalCapacity = bottlesIncome.Length * bootleCapacity;
  12.         double waterInBottles = totalCapacity - bottlesIncome.Sum();
  13.  
  14.         if (waterInBottles <= totalWater) ///Enough water
  15.         {
  16.             Console.WriteLine("Enough water!");
  17.             Console.WriteLine("Water left: {0}l.", totalWater - waterInBottles);
  18.         }
  19.         else  //Not enough water
  20.         {
  21.             double notEnoughtCapacity = totalCapacity - totalWater;
  22.  
  23.             int ostatak = (int)notEnoughtCapacity % (int)bootleCapacity;
  24.             int bootles;
  25.  
  26.             if (ostatak == 0)
  27.             {
  28.                 bootles = (int)notEnoughtCapacity / (int)bootleCapacity;
  29.             }
  30.             else
  31.             {
  32.                 bootles = (int)notEnoughtCapacity / (int)bootleCapacity;
  33.                 bootles++;
  34.             }
  35.             int[] x = new int[bootles];
  36.             if ((int)totalWater % 2 == 0) //even
  37.             {
  38.                 int plus = bottlesIncome.Length - bootles;
  39.  
  40.                 for (int i = bootles - 1; i >= 0; i--)  // show direction of filing from left to right
  41.                 {
  42.                     x[i] = i + plus;
  43.                 }
  44.             }
  45.             else//odd
  46.             {
  47.                 for (int i = bootles - 1; i >= 0; i--)   // show direction of filing from right to left
  48.                 {
  49.                     x[i] = bootles - 1 - i;
  50.                 }
  51.             }
  52.             Console.WriteLine("We need more water!");
  53.             Console.WriteLine("Bottles left: {0}", bootles);
  54.             Console.WriteLine("With indexes: {0}", string.Join(", ", x));
  55.             Console.WriteLine("We need {0} more liters!", notEnoughtCapacity);
  56.  
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement