Advertisement
North_Point

03 – Endurance Rally EXAM

Aug 7th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _03.Endurance_Rally
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var drivers = Console.ReadLine().Split(' ').ToList();
  14.  
  15.             var trackLayout = Console.ReadLine().Split(' ')
  16.                 .Select(double.Parse).ToList();
  17.  
  18.             var checkpoint = Console.ReadLine().Split(' ')
  19.                 .Select(int.Parse).ToList();
  20.           //  var result = new Dictionary<string, double>();
  21.  
  22.             double number = 0;
  23.             for (int i = 0; i < drivers.Count; i++)
  24.             {
  25.                
  26.                 char firstLetter = drivers[i][0];
  27.                 number = (int)firstLetter;
  28.  
  29.                 for (int j = 0; j < trackLayout.Count; j++)
  30.                 {
  31.                     if (checkpoint.Contains(j))
  32.                     {
  33.                         number += trackLayout[j];
  34.                     }
  35.                     else
  36.                     {
  37.                         number -= trackLayout[j];
  38.                         if (number <= 0)
  39.                         {
  40.                             Console.WriteLine("{0} - reached {1}",drivers[i],j);
  41.                             break;
  42.                         }
  43.                     }
  44.                 }
  45.                 if (number > 0)
  46.                 {
  47.                     Console.WriteLine("{0} - fuel left {1:f2}",drivers[i],number);
  48.                 }
  49.                
  50.             }
  51.           //  foreach (var item in result)
  52.           //  {
  53.           //      if (item.Value > 0)
  54.           //      {
  55.           //          Console.WriteLine($"{item.Key} - fuel left {item.Value:f2}");
  56.           //      }
  57.           //      else
  58.           //      {
  59.           //          Console.WriteLine($"{item.Key} - reached 0");
  60.           //      }
  61.           //  }
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement