Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace Prob_03_Endurance_Rally
- {
- class MainClass
- {
- public static void Main(string[] args)
- {
- List<Racer> allRacers = new List<Racer>();
- var racersNames = Console.ReadLine().Split().ToList();
- foreach (var racerName in racersNames)
- {
- allRacers.Add(new Racer(racerName));
- }
- var zones = Console.ReadLine().Split().Select(double.Parse).ToList();
- var checkpoints = Console.ReadLine().Split().Select(int.Parse).ToList();
- foreach (var racer in allRacers)
- {
- for (int i = 0; i < zones.Count; i++)
- {
- if (checkpoints.Contains(i))
- {
- racer.Fuel += zones[i];
- }
- else
- {
- racer.Fuel -= zones[i];
- if (racer.Fuel <= 0)
- {
- racer.ReachedIndex = i;
- break;
- }
- }
- }
- if (racer.ReachedIndex == -1)
- {
- Console.WriteLine("{0} - fuel left {1:f2}", racer.Name, racer.Fuel);
- }
- else
- {
- Console.WriteLine("{0} - reached {1}", racer.Name, racer.ReachedIndex);
- }
- }
- }
- }
- class Racer
- {
- public Racer(string name)
- {
- this.Name = name;
- int fuel = name[0];
- this.Fuel = fuel;
- this.ReachedIndex = -1;
- }
- public string Name { get; set; }
- public double Fuel { get; set; }
- public int ReachedIndex { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment