Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _03.EnduranceRally
- {
- class Driver
- {
- public string Name { get; set; }
- public double Fuel { get; set; }
- public int IndexReached { get; set; }
- }
- class EnduranceRally
- {
- static void Main(string[] args)
- {
- List<Driver> all = new List<Driver>();
- string[] drivers = Console.ReadLine().Split(' ');
- double[] numbers = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
- int[] checkpoints = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- foreach (string driver in drivers)
- {
- Driver currentDriver = new Driver();
- currentDriver.Name = driver;
- currentDriver.Fuel = driver[0];
- for (int i = 0; i < numbers.Length; i++)
- {
- currentDriver.IndexReached = i;
- if (checkpoints.Contains(i))
- {
- currentDriver.Fuel = currentDriver.Fuel + numbers[i];
- }
- else
- {
- currentDriver.Fuel = currentDriver.Fuel - numbers[i];
- }
- if (currentDriver.Fuel < 0)
- {
- break;
- }
- }
- all.Add(currentDriver);
- }
- foreach (Driver driver in all)
- {
- if (driver.Fuel < 0)
- {
- Console.WriteLine("{0} - reached {1}", driver.Name, driver.IndexReached);
- }
- else
- {
- Console.WriteLine("{0} - fuel left {1:f2}", driver.Name, driver.Fuel);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement