Advertisement
AlexTasev

EnduranceRally_ExPrepI

Jun 30th, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _EnduranceRally_ExPrepI
  5. {
  6.     class Program
  7.     {
  8.         static void Main()
  9.         {
  10.             string[] drivers = Console.ReadLine().Split();
  11.             double[] zones = Console.ReadLine().Split().Select(double.Parse).ToArray();
  12.             int[] checkPoints = Console.ReadLine().Split().Select(int.Parse).ToArray();
  13.  
  14.             for (int i = 0; i < drivers.Length; i++)
  15.             {
  16.                 string name = drivers[i];
  17.                 double fuel = name[0];
  18.                 int endPosition = 0;
  19.                 double zoneValue;
  20.  
  21.                 for (int index = 0; index < zones.Length; index++)
  22.                 {
  23.                     zoneValue = zones[index];
  24.  
  25.                     if (checkPoints.Contains(index))
  26.                     {
  27.                         fuel += zoneValue;
  28.                     }
  29.                     else
  30.                     {
  31.                         fuel -= zoneValue;
  32.                     }
  33.  
  34.                     if (fuel <= 0)
  35.                     {
  36.                         endPosition = index;
  37.                         break;
  38.                     }
  39.                 }
  40.  
  41.                 if (fuel >= 0)
  42.                 {
  43.                     Console.WriteLine($"{name} - fuel left {fuel:f2}");
  44.                 }
  45.                 else
  46.                 {
  47.                     Console.WriteLine($"{name} - reached {endPosition}");
  48.                 }
  49.             }
  50.         }
  51.     }
  52. }   //  80 %
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement