Advertisement
ghostd0g

Untitled

Feb 26th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Numerics;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Exercise3
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             Dictionary<string, Dictionary<double, int>> players = new Dictionary<string, Dictionary<double, int>>();
  15.  
  16.             string[] drivers = Console.ReadLine().Split(' ');
  17.  
  18.             double[] zones = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
  19.  
  20.             List<int> checkpoints = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  21.  
  22.            
  23.  
  24.             for (int a = 0; a < drivers.Length; a++)
  25.             {
  26.                 double playerFuel = drivers[a].First();
  27.                 Dictionary<double, int> fuelAndPos = new Dictionary<double, int>();
  28.  
  29.  
  30.                 for (int c = 0; c < zones.Length; c++)
  31.                 {
  32.                     if (checkpoints.Contains(c))
  33.                     {
  34.                         playerFuel += zones[c];
  35.                     }
  36.                     else
  37.                     {
  38.                         playerFuel -= zones[c];
  39.                         if (playerFuel<=0)
  40.                         {
  41.  
  42.                             fuelAndPos.Add(playerFuel, c);
  43.                             players.Add(drivers[a], fuelAndPos);
  44.                             break;
  45.                         }
  46.                     }
  47.                    
  48.                 }
  49.  
  50.                 if (playerFuel>0)
  51.                 {
  52.                     fuelAndPos.Add(playerFuel, -1);
  53.                     players.Add(drivers[a], fuelAndPos);
  54.                 }
  55.                
  56.             }
  57.  
  58.             foreach (var driver in players)
  59.             {
  60.                 if (driver.Value.Values.Contains(-1))
  61.                 {
  62.                     Console.WriteLine($"{driver.Key} - fuel left {driver.Value.Keys.Min():f2}");
  63.                 }
  64.                 else
  65.                 {
  66.                     Console.WriteLine($"{driver.Key} - reached {driver.Value.Values.Min()}");
  67.                 }
  68.             }
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement