Advertisement
YavorGrancharov

Problem_3___Endurance_Rally

Nov 1st, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Problem_3___Endurance_Rally
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] drivers = Console.ReadLine().Split().ToArray();
  14.             double[] fuel = Console.ReadLine().Split().Select(double.Parse).ToArray();
  15.             int[] checkpoints = Console.ReadLine().Split().Select(int.Parse).ToArray();
  16.  
  17.             double startingFuel = 0.0;
  18.             foreach (var driver in drivers)
  19.             {
  20.                 startingFuel = Convert.ToInt32(driver.FirstOrDefault());
  21.                 for (int i = 0; i < fuel.Length; i++)
  22.                 {
  23.                     if (checkpoints.Contains(i))
  24.                     {
  25.                         startingFuel += fuel[i];
  26.                     }
  27.                     else
  28.                     {
  29.                         startingFuel -= fuel[i];
  30.                     }
  31.                     if (startingFuel <= 0)
  32.                     {
  33.                         Console.WriteLine("{0} - reached {1}",driver,i);
  34.                         break;
  35.                     }
  36.                 }
  37.                 if (startingFuel > 0)
  38.                 {
  39.                     Console.WriteLine("{0} - fuel left {1:F2}", driver,startingFuel);
  40.                 }
  41.             }          
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement