Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.64 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7. using System.Globalization;
  8.  
  9. namespace ExamPreparation2
  10. {
  11.     public class Program
  12.     {
  13.         public static void Main()
  14.         {
  15.             bool end = false;
  16.             var drivers = Console.ReadLine().Split().ToArray();
  17.             var zones = Console.ReadLine().Split().Select(double.Parse).ToArray();
  18.             var checkPoints = Console.ReadLine().Split().Select(double.Parse).ToArray();
  19.             foreach (var driver in drivers)
  20.             {
  21.                 double fuel = driver[0];
  22.                 for (int i = 0; i < zones.Length; i++)
  23.                 {
  24.                     var index = i;
  25.                     if(checkPoints.Contains(index))
  26.                     {
  27.                         foreach (var item in checkPoints)
  28.                         {
  29.                             if (index == item)
  30.                             {
  31.                                 fuel += zones[i];
  32.                             }
  33.                         }
  34.                     }
  35.                     else
  36.                     {
  37.                         fuel -= zones[i];
  38.                         if (fuel <= 0)
  39.                         {
  40.                             end = true;
  41.                             Console.WriteLine("{0} - reached {1}",driver,i);
  42.                             break;
  43.                         }
  44.                     }
  45.                 }
  46.                 Console.WriteLine("{0} - fuel left {1:f2}",driver,fuel);
  47.                 if(end) break;
  48.             }
  49.  
  50.  
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement