Advertisement
Guest User

Untitled

a guest
Jun 10th, 2016
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 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 BottlesFilling
  8. {
  9. class Program
  10. {
  11. static void Main()
  12. {
  13. var totalAmountOfWater = int.Parse(Console.ReadLine());
  14. decimal[] itemsInTheArray = Console.ReadLine().Split(' ').Select(decimal.Parse).ToArray();
  15. int bottleCapacity = int.Parse(Console.ReadLine());
  16. var bottlesLeft = 0;
  17. var indexesOfLeftBottles = new List<int>();
  18.  
  19. decimal litersFilled = 0;
  20. if (totalAmountOfWater % 2 == 0)
  21. {
  22. for (int i = 0; i < itemsInTheArray.Length; i++)
  23. {
  24. litersFilled += bottleCapacity - itemsInTheArray[i];
  25. if (litersFilled > totalAmountOfWater)
  26. {
  27. bottlesLeft++;
  28. indexesOfLeftBottles.Add(i);
  29. }
  30. }
  31. }
  32. else
  33. {
  34. for (int i = itemsInTheArray.Length - 1; i >= 0; i--)
  35. {
  36. litersFilled += bottleCapacity - itemsInTheArray[i];
  37. if (litersFilled > totalAmountOfWater)
  38. {
  39. bottlesLeft++;
  40. indexesOfLeftBottles.Add(i);
  41. }
  42. }
  43. }
  44. if (litersFilled > totalAmountOfWater)
  45. {
  46. Console.WriteLine("We need more water!");
  47. Console.WriteLine($"Bottles left: {bottlesLeft}");
  48. Console.WriteLine($"With indexes: {string.Join(", ", indexesOfLeftBottles)}");
  49. Console.WriteLine($"We need {litersFilled - totalAmountOfWater} more liters!");
  50. }
  51. else
  52. {
  53. Console.WriteLine("Enough water!");
  54. Console.WriteLine($"Water left: {totalAmountOfWater - litersFilled}l.");
  55. }
  56.  
  57.  
  58. }
  59.  
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement