ramsess90

Endurance Rally

Jul 5th, 2017
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace Prob_03_Endurance_Rally
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.             List<Racer> allRacers = new List<Racer>();
  12.             var racersNames = Console.ReadLine().Split().ToList();
  13.             foreach (var racerName in racersNames)
  14.             {
  15.                 allRacers.Add(new Racer(racerName));
  16.             }
  17.             var zones = Console.ReadLine().Split().Select(double.Parse).ToList();
  18.             var checkpoints = Console.ReadLine().Split().Select(int.Parse).ToList();
  19.  
  20.             foreach (var racer in allRacers)
  21.             {
  22.                 for (int i = 0; i < zones.Count; i++)
  23.                 {
  24.                     if (checkpoints.Contains(i))
  25.                     {
  26.                         racer.Fuel += zones[i];
  27.                     }
  28.                     else
  29.                     {
  30.                         racer.Fuel -= zones[i];
  31.                         if (racer.Fuel <= 0)
  32.                         {
  33.                             racer.ReachedIndex = i;
  34.                             break;
  35.                         }
  36.                     }
  37.                 }
  38.                 if (racer.ReachedIndex == -1)
  39.                 {
  40.                     Console.WriteLine("{0} - fuel left {1:f2}", racer.Name, racer.Fuel);
  41.                 }
  42.                 else
  43.                 {
  44.                     Console.WriteLine("{0} - reached {1}", racer.Name, racer.ReachedIndex);
  45.                 }
  46.             }
  47.         }
  48.     }
  49.  
  50.     class Racer
  51.     {
  52.         public Racer(string name)
  53.         {
  54.             this.Name = name;
  55.             int fuel = name[0];
  56.             this.Fuel = fuel;
  57.             this.ReachedIndex = -1;
  58.         }
  59.  
  60.         public string Name { get; set; }
  61.  
  62.         public double Fuel { get; set; }
  63.  
  64.         public int ReachedIndex { get; set; }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment