Advertisement
jordan3900

Untitled

Jul 26th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 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 _02.SoftUniWaterSupplies
  8. {
  9. class SoftuniWatterSupplies
  10. {
  11. static void Main(string[] args)
  12. {
  13. double amountOfWater = int.Parse(Console.ReadLine());
  14. List<double> bottles = Console.ReadLine().Split().Select(double.Parse).ToList();
  15. double bottlesCapacity = double.Parse(Console.ReadLine());
  16. int bottlesLeft = 0;
  17. double neededL = 0;
  18. List<int> index = new List<int>();
  19.  
  20. if (amountOfWater%2==0)
  21. {
  22. for (int i = 0; i < bottles.Count; i++)
  23. {
  24. while (bottles[i] != bottlesCapacity && amountOfWater != 0)
  25. {
  26. double diff = bottlesCapacity - bottles[i];
  27. if (diff<=amountOfWater)
  28. {
  29. bottles[i] += diff;
  30. amountOfWater -= diff;
  31. }
  32. }
  33. if (amountOfWater==0)
  34. {
  35. break;
  36. }
  37. }
  38. List<double> check = bottles.Where(a => a == bottlesCapacity).ToList();
  39.  
  40. if (check.Count== bottles.Count)
  41. {
  42. Console.WriteLine("Enough water!");
  43. Console.WriteLine($"Water left: {amountOfWater}l.");
  44. }
  45. else
  46. {
  47. Console.WriteLine("We need more water!");
  48. for (int i = 0; i < bottles.Count; i++)
  49. {
  50. if (bottles[i]!=bottlesCapacity)
  51. {
  52. index.Add(i);
  53. bottlesLeft++;
  54. neededL += bottlesCapacity - bottles[i];
  55. }
  56. }
  57. Console.WriteLine($"Bottles left: {bottlesLeft}");
  58. Console.WriteLine($"With indexes: {string.Join(", ",index)}");
  59. Console.WriteLine($"We need {neededL} more liters!");
  60. }
  61.  
  62. }
  63. else
  64. {
  65. for (int i = bottles.Count-1; i >=0 ; i--)
  66. {
  67. while (bottles[i] != bottlesCapacity && amountOfWater != 0)
  68. {
  69. double diff = bottlesCapacity - bottles[i];
  70. if (diff <= amountOfWater)
  71. {
  72. bottles[i] += diff;
  73. amountOfWater -= diff;
  74. }
  75. }
  76. if (amountOfWater == 0)
  77. {
  78. break;
  79. }
  80. }
  81. List<double> check = bottles.Where(a => a == bottlesCapacity).ToList();
  82.  
  83. if (check.Count == bottles.Count)
  84. {
  85. Console.WriteLine("Enough water!");
  86. Console.WriteLine($"Water left: {amountOfWater}l.");
  87. }
  88. else
  89. {
  90. Console.WriteLine("We need more water!");
  91. for (int i = bottles.Count-1; i >=0; i--)
  92. {
  93. if (bottles[i] != bottlesCapacity)
  94. {
  95. index.Add(i);
  96. bottlesLeft++;
  97. neededL += bottlesCapacity - bottles[i];
  98. }
  99. }
  100. Console.WriteLine($"Bottles left: {bottlesLeft}");
  101. Console.WriteLine($"With indexes: {string.Join(", ", index)}");
  102. Console.WriteLine($"We need {neededL} more liters!");
  103. }
  104. }
  105.  
  106. }
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement