Advertisement
Guest User

Untitled

a guest
Sep 15th, 2016
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 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 SoftUniWaterSupplies
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. double water = int.Parse(Console.ReadLine());
  14. var bottles = Console.ReadLine().Split(' ').Select(double.Parse).ToList();
  15. double capacity = int.Parse(Console.ReadLine());
  16. var bottlesLeft = new List<int>();
  17. double waterNeeded = 0;
  18.  
  19.  
  20.  
  21. if (water%2 == 0)
  22. {
  23. //water is even, start from 0
  24. for (int i = 0; i < bottles.Count; i++)
  25. {
  26. double currentRefill = capacity - bottles[i];
  27. if (water >= currentRefill)
  28. {
  29. water -= currentRefill;
  30. }
  31. else
  32. {
  33. waterNeeded += currentRefill - water;
  34. water = 0;
  35. bottlesLeft.Add(i);
  36. }
  37. }
  38. }
  39. else
  40. {
  41. //water is odd, start from Length
  42. for (int i = bottles.Count-1; i >= 0; i--)
  43. {
  44. double currentRefill = capacity - bottles[i];
  45. if (water >= currentRefill)
  46. {
  47. water -= currentRefill;
  48. }
  49. else
  50. {
  51. waterNeeded += currentRefill - water;
  52. water = 0;
  53. bottlesLeft.Add(i);
  54. }
  55. }
  56. }
  57.  
  58. //Print results
  59. if (waterNeeded == 0)
  60. {
  61. //Enough water
  62. Console.Out.WriteLine("Enough water!");
  63. Console.Out.WriteLine($"Water left: {water}l.");
  64. }
  65. else
  66. {
  67. //not enough water
  68. Console.Out.WriteLine("We need more water!");
  69. Console.Out.WriteLine($"Bottles left: {bottlesLeft.Count}");
  70. Console.Out.WriteLine($"With indexes: {string.Join(", ",bottlesLeft)}");
  71. Console.Out.WriteLine($"We need {waterNeeded} more liters!");
  72. }
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement