Guest User

Untitled

a guest
Feb 18th, 2017
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.85 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 _03.EnduranceRally
  8. {
  9.     class Program
  10.     {
  11.         static void Main()
  12.         {
  13.             string[] drivers = Console.ReadLine()
  14.                 .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  15.             double[] zones = Console.ReadLine()
  16.                 .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  17.                 .Select(double.Parse)
  18.                 .ToArray();
  19.             List<int> checkpoints = Console.ReadLine()
  20.                 .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  21.                 .Select(int.Parse)
  22.                 .ToList();
  23.  
  24.             foreach (string driver in drivers)
  25.             {
  26.                 bool outOfFuel = false;
  27.                 int reachedIndex = 0;
  28.                 double fuel = driver[0];
  29.  
  30.                 for (int zoneIndex = 0; zoneIndex < zones.Length; zoneIndex++)
  31.                 {
  32.                     if (checkpoints.Contains(zoneIndex))
  33.                     {
  34.                         fuel += zones[zoneIndex];
  35.                     }
  36.                     else
  37.                     {
  38.                         fuel -= zones[zoneIndex];
  39.                     }
  40.  
  41.                     if (fuel <= 0)
  42.                     {
  43.                         outOfFuel = true;
  44.                         reachedIndex = zoneIndex;
  45.                         break;
  46.                     }
  47.  
  48.                 }
  49.  
  50.                 if (outOfFuel == true)
  51.                 {
  52.                     Console.WriteLine($"{driver} - reached {reachedIndex}");
  53.                 }
  54.                 else
  55.                 {
  56.                     Console.WriteLine("{0} - fuel left {1:F2}", driver, fuel);
  57.                 }
  58.  
  59.             }
  60.  
  61.         }
  62.     }
  63. }
Add Comment
Please, Sign In to add comment