Advertisement
fbinnzhivko

SoftUni Water Supplies

Sep 15th, 2016
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _2
  8.     {
  9.     class Program
  10.         {
  11.         static void Main(string[] args)
  12.             {
  13.             decimal amountOfWater = decimal.Parse(Console.ReadLine());
  14.             decimal[] bottlesToFill = Console.ReadLine().Split(' ').Select(decimal.Parse).ToArray();
  15.             int capacityOfBottles =int.Parse(Console.ReadLine());
  16.             List<int> bottToFill = new List<int>();
  17.  
  18.             if (amountOfWater%2==0)
  19.                 {
  20.                 for (int i = 0; i < bottlesToFill.Length; i++)
  21.                     {
  22.                     if (bottlesToFill[i]==capacityOfBottles)
  23.                         {
  24.                         continue;
  25.                         }  
  26.                     else
  27.                         {
  28.                         decimal checkForWater =  amountOfWater-(capacityOfBottles-bottlesToFill[i]);
  29.                         if (checkForWater>0)
  30.                             {
  31.                             decimal litters = bottlesToFill[i];
  32.                             bottlesToFill[i]+=capacityOfBottles-litters;
  33.                             amountOfWater-=capacityOfBottles-litters;
  34.                             }
  35.                         else if (amountOfWater>0)
  36.                             {
  37.                             bottlesToFill[i]+=amountOfWater;
  38.                             amountOfWater=0;
  39.                             }
  40.                         }
  41.                     if (amountOfWater==0)
  42.                         {
  43.                         for (int h = 0; h < bottlesToFill.Length; h++)
  44.                             {
  45.                             if (bottlesToFill[h]<capacityOfBottles)
  46.                                 {
  47.                                 bottToFill.Add(h);
  48.                                 }
  49.                             }
  50.                         break;
  51.                         }
  52.                     }
  53.                 }
  54.  
  55.             if (amountOfWater%2!=0)
  56.                 {
  57.                 for (int i = bottlesToFill.Length-1; i >= 0; i--)
  58.                     {
  59.                     if (bottlesToFill[i]==capacityOfBottles)
  60.                         {
  61.                         break;
  62.                         }  
  63.                     else
  64.                         {
  65.                         decimal checkForWater =  amountOfWater-(capacityOfBottles-bottlesToFill[i]);
  66.                         if (checkForWater>0)
  67.                             {
  68.                             decimal litters = bottlesToFill[i];
  69.                             bottlesToFill[i]+=capacityOfBottles-litters;
  70.                             amountOfWater-=capacityOfBottles-litters;
  71.                             }
  72.                         else if (amountOfWater>0)
  73.                             {
  74.                             bottlesToFill[i]+=amountOfWater;
  75.                             amountOfWater=0;
  76.                             }
  77.                         }
  78.                        
  79.                     if (amountOfWater==0)
  80.                         {
  81.                         for (int h = bottlesToFill.Length-1; h >= 0; h--)
  82.                             {
  83.                             if (bottlesToFill[h]<capacityOfBottles)
  84.                                 {
  85.                                 bottToFill.Add(h);
  86.                                 }
  87.                             }
  88.                         break;
  89.                         }
  90.                     }
  91.                 }
  92.  
  93.             int checkForList = bottToFill.Count;
  94.             if (checkForList==0)
  95.                 {
  96.                 Console.WriteLine("Enough water!\nWater left: {0}l.",amountOfWater);
  97.                 }
  98.             else
  99.                 {
  100.                 decimal waterNeed = 0;
  101.                 for (int i = 0; i < bottToFill.Count; i++)
  102.                     {
  103.                     int index = bottToFill[i];
  104.                     if (bottlesToFill[index]<capacityOfBottles)
  105.                         {
  106.                         waterNeed+=capacityOfBottles-bottlesToFill[index];
  107.                         }
  108.                     }
  109.                 Console.WriteLine("We need more water!\nBottles left: {0}\nWith indexes: {1}\nWe need {2} more liters!",checkForList,string.Join(", ",bottToFill),waterNeed);
  110.                 }
  111.  
  112.  
  113.             }
  114.         }
  115.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement