Advertisement
Guest User

03. Endurance Rally - Fixed

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