Advertisement
EmoRz

EnduranceRally

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