HristoGrigorov

Untitled

Jul 5th, 2017
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 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 _03.EnduranceRally
  8. {
  9. public class Startup
  10. {
  11. public static void Main()
  12. {
  13. var drivers = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  14. var zones = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(decimal.Parse).ToArray();
  15. var checkpointsIndexes = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
  16.  
  17.  
  18. foreach (var driver in drivers)
  19. {
  20.  
  21. decimal initialFuel = (decimal)driver[0];
  22. int position = 0;
  23. for (int i = 0; i < zones.Length; i++)
  24. {
  25. if (checkpointsIndexes.Contains(i))
  26. {
  27. initialFuel += zones[i];
  28. }
  29. else
  30. {
  31. initialFuel -= zones[i];
  32. }
  33. if (initialFuel <= 0)
  34. {
  35. position = i;
  36. break;
  37. }
  38. }
  39. if (initialFuel <= 0)
  40. {
  41. Console.WriteLine($"{driver} reached {position}");
  42. }
  43. else
  44. {
  45. Console.WriteLine($"{driver} - fuel left {initialFuel:f2}");
  46. }
  47. }
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment