Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.96 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 Driver
  10.     {
  11.         public string Name { get; set; }
  12.         public double Fuel { get; set; }
  13.         public int IndexReached { get; set; }
  14.     }
  15.  
  16.     class EnduranceRally
  17.     {
  18.         static void Main(string[] args)
  19.         {
  20.             List<Driver> all = new List<Driver>();
  21.             string[] drivers = Console.ReadLine().Split(' ');
  22.             double[] numbers = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
  23.             int[] checkpoints = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  24.  
  25.             foreach (string driver in drivers)
  26.             {
  27.                 Driver currentDriver = new Driver();
  28.  
  29.                 currentDriver.Name = driver;
  30.                 currentDriver.Fuel = driver[0];
  31.  
  32.                 for (int i = 0; i < numbers.Length; i++)
  33.                 {
  34.                     currentDriver.IndexReached = i;
  35.  
  36.                     if (checkpoints.Contains(i))
  37.                     {
  38.                         currentDriver.Fuel = currentDriver.Fuel + numbers[i];
  39.                     }
  40.                     else
  41.                     {
  42.                         currentDriver.Fuel = currentDriver.Fuel - numbers[i];
  43.                     }
  44.  
  45.                     if (currentDriver.Fuel < 0)
  46.                     {
  47.                         break;
  48.                     }
  49.                 }
  50.  
  51.                 all.Add(currentDriver);
  52.             }
  53.  
  54.             foreach (Driver driver in all)
  55.             {
  56.                 if (driver.Fuel < 0)
  57.                 {
  58.                     Console.WriteLine("{0} - reached {1}", driver.Name, driver.IndexReached);
  59.                 }
  60.                 else
  61.                 {
  62.                     Console.WriteLine("{0} - fuel left {1:f2}", driver.Name, driver.Fuel);
  63.                 }
  64.             }
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement