Advertisement
_CodeBehind

Endurance rally

Jun 28th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1.  var drivers = Console.ReadLine()
  2.                 .Split(new[]  { ' ' },StringSplitOptions.RemoveEmptyEntries);
  3.  
  4.             var track = Console.ReadLine()
  5.                 .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  6.                 .Select(double.Parse)
  7.                 .ToArray();
  8.  
  9.             var checkpoints = Console.ReadLine()
  10.                 .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  11.                 .Select(int.Parse)
  12.                 .ToArray();
  13.  
  14.             foreach (var driver in drivers)
  15.             {
  16.                 double fuel = driver.First();
  17.  
  18.                 for (int i = 0; i < track.Length; i++)
  19.                 {
  20.                     if (checkpoints.Contains(i))
  21.                     {
  22.                         fuel += track[i];
  23.                     }
  24.                     else
  25.                     {
  26.                         fuel -= track[i];
  27.                     }
  28.                     if (fuel<=0)
  29.                     {
  30.                         Console.WriteLine($"{driver} - reached {i}");
  31.                         break;
  32.                     }
  33.                 }
  34.                 if (fuel>0)
  35.                 {
  36.                     Console.WriteLine($"{driver} - fuel left {fuel:F2}");
  37.                 }
  38.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement