Advertisement
simonradev

TruckTour

May 26th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.40 KB | None | 0 0
  1. namespace TruckTour
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.     using System.Text;
  7.     using System.Threading.Tasks;
  8.    
  9.     public class Startup
  10.     {
  11.         public static void Main()
  12.         {
  13.             Queue<GasPump> allGasPumps = new Queue<GasPump>();
  14.  
  15.             int numberOfInputs = int.Parse(Console.ReadLine());
  16.             for (int currInputLine = 0; currInputLine < numberOfInputs; currInputLine++)
  17.             {
  18.                 allGasPumps.Enqueue(new GasPump(currInputLine, Console.ReadLine()
  19.                                                                .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  20.                                                                .Select(int.Parse)
  21.                                                                .ToArray()));
  22.             }
  23.  
  24.             int countOfPumpsPassedBy = 0;
  25.             int gasPumpsToStopBy = allGasPumps.Count;
  26.  
  27.             int totalGasoline = 0;
  28.  
  29.             while (countOfPumpsPassedBy != gasPumpsToStopBy)
  30.             {
  31.                 GasPump gasPump = allGasPumps.Dequeue();
  32.  
  33.                 totalGasoline += gasPump.Gasoline;
  34.  
  35.                 if (totalGasoline >= gasPump.DistanceToTravel)
  36.                 {
  37.                     totalGasoline -= gasPump.DistanceToTravel;
  38.  
  39.                     countOfPumpsPassedBy++;
  40.                 }
  41.                 else
  42.                 {
  43.                     countOfPumpsPassedBy = 0;
  44.  
  45.                     totalGasoline = 0;
  46.                 }
  47.  
  48.                 allGasPumps.Enqueue(gasPump);
  49.             }
  50.  
  51.             Console.WriteLine(allGasPumps.Peek().Index);
  52.         }
  53.     }
  54.  
  55.     public class GasPump
  56.     {
  57.         private int gasoline;
  58.         private int distanceToTravel;
  59.  
  60.         private int index;
  61.  
  62.         public GasPump(int index, params int[] gasPumpInfo)
  63.         {
  64.             this.gasoline = gasPumpInfo[0];
  65.             this.distanceToTravel = gasPumpInfo[1];
  66.  
  67.             this.index = index;
  68.         }
  69.  
  70.         public int Gasoline
  71.         {
  72.             get { return this.gasoline; }
  73.             set { this.gasoline = value; }
  74.         }
  75.  
  76.         public int DistanceToTravel
  77.         {
  78.             get { return this.distanceToTravel; }
  79.             set { this.distanceToTravel = value; }
  80.         }
  81.  
  82.         public int Index
  83.         {
  84.             get { return this.index; }
  85.         }
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement