Advertisement
Guest User

03. Endurance Rally

a guest
Aug 8th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5.  
  6. class EnduranceRally
  7. {
  8.     static void Main()
  9.     {
  10.         var drivers = Console.ReadLine().Split(' ');
  11.         var zone = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
  12.         var checkpointsIndex = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  13.  
  14.         var lastZone = 0;
  15.  
  16.         for (int i = 0; i < drivers.Length; i++)
  17.         {
  18.             var isFinished = true;
  19.             var fuelLeft = (double)drivers[i][0];
  20.  
  21.             for (int j = 0; j < zone.Length; j++)
  22.             {
  23.                 if (checkpointsIndex.Contains(j)) fuelLeft += zone[j];
  24.                 else fuelLeft -= zone[j];
  25.  
  26.                 if (fuelLeft < 0)
  27.                 {
  28.                     lastZone = j;
  29.                     isFinished = false;
  30.                     break;
  31.                 }
  32.             }
  33.  
  34.             if (isFinished) Console.WriteLine($"{drivers[i]} - fuel left {fuelLeft:f2}");
  35.             else Console.WriteLine($"{drivers[i]} - reached {lastZone}");
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement