Advertisement
A_E_Ivanov

TruckStop

Sep 22nd, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace _14.TruckTour
  6. {
  7.     public class Program
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.             int petrolStations = int.Parse(Console.ReadLine());
  12.  
  13.             Queue<string> data = new Queue<string>();
  14.  
  15.             for (int i = 0; i < petrolStations; i++)
  16.             {
  17.                 string text = Console.ReadLine();
  18.                 data.Enqueue(text);
  19.             }
  20.  
  21.             int stationNumber = 0;
  22.            
  23.             int total = 0;
  24.  
  25.             while (data.Any())
  26.             {
  27.                 Queue<string> innerData = new Queue<string>();
  28.  
  29.                 string start = data.Peek();
  30.                 int[] information = start.Split().Select(int.Parse).ToArray();
  31.  
  32.                 int fuel = information[0];
  33.                 int distance = information[1];
  34.  
  35.                
  36.                 total += fuel;
  37.                 total -= distance;
  38.  
  39.                 if (total > -1)
  40.                 {
  41.                     innerData.Enqueue(start);
  42.                     data.Dequeue();                    
  43.                 }
  44.                 else
  45.                 {                  
  46.                     innerData.Enqueue(start);
  47.                     data.Dequeue();
  48.  
  49.                     for (int i = 0; i < innerData.Count; i++)
  50.                     {
  51.                         string newData = innerData.Dequeue();
  52.                         data.Enqueue(newData);
  53.                     }
  54.  
  55.                     total = 0;
  56.                     stationNumber++;
  57.                 }
  58.                
  59.             }
  60.  
  61.             Console.WriteLine(stationNumber);
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement