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.Endurance_Rally
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] driverNames = Console.ReadLine().Split();
- Driver[] drivers = ReturnDrivers(driverNames);
- double[] trackLayout = Console.ReadLine()
- .Split()
- .Select(double.Parse)
- .ToArray();
- int lastZone = trackLayout.Length - 1;
- int[] checkpoints = Console.ReadLine()
- .Split()
- .Select(int.Parse)
- .ToArray();
- for (int i = 0; i < trackLayout.Length; i++)
- {
- for (int j = 0; j < drivers.Length; j++)
- {
- bool isCheckpoint = checkpoints.Contains(i);
- if (isCheckpoint && drivers[j].fuel > 0)
- {
- drivers[j].fuel += trackLayout[i];
- drivers[j].zoneReached = i;
- }
- else
- {
- if (drivers[j].fuel > 0)
- {
- drivers[j].fuel -= trackLayout[i];
- drivers[j].zoneReached = i;
- }
- }
- }
- }
- PrintOutput(drivers, lastZone);
- }
- static Driver[] ReturnDrivers(string[] driverNames)
- {
- int driversCount = driverNames.Length;
- Driver[] drivers = new Driver[driversCount];
- for (int i = 0; i < driversCount; i++)
- {
- string currentName = driverNames[i];
- byte currentFuel = (byte)currentName[0];
- drivers[i] = new Driver()
- {
- name = currentName,
- fuel = currentFuel,
- zoneReached = 0
- };
- }
- return drivers;
- }
- static void PrintOutput(Driver[] drivers, int trackLength)
- {
- foreach (Driver item in drivers)
- {
- if (item.zoneReached == trackLength && item.fuel > 0)
- {
- Console.WriteLine($"{item.name} - fuel left {item.fuel:f2}");
- }
- else
- {
- Console.WriteLine($"{item.name} - reached {item.zoneReached}");
- }
- }
- }
- }
- class Driver
- {
- public string name { get; set; }
- public double fuel { get; set; }
- public int zoneReached { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment