Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.19 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5.  
  6. namespace ConsoleApp87
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string[] vehicles = Console.ReadLine().Split(new char[] { ' '}, StringSplitOptions.RemoveEmptyEntries);
  13.  
  14.             var queue = new Queue<string>(vehicles);
  15.             var stack = new Stack<string>();
  16.  
  17.             while (true)
  18.             {
  19.                 string[] input = Console.ReadLine().Split('-');
  20.  
  21.                 switch (input[0])
  22.                 {
  23.                     case "Service":
  24.                         if (queue.Count != 0)
  25.                         {
  26.                             Console.WriteLine($"Vehicle {queue.Peek()} got served.");
  27.                             stack.Push(queue.Dequeue());
  28.                         }                      
  29.                         break;
  30.                     case "CarInfo":
  31.                         if (queue.Contains(input[1]))
  32.                         {
  33.                             Console.WriteLine($"Still waiting for service.");
  34.                         }
  35.                         else
  36.                         {
  37.                             if (stack.Contains(input[1]))
  38.                             {
  39.                                 Console.WriteLine("Served.");
  40.                             }                          
  41.                         }
  42.                         break;
  43.                     case "History":
  44.                         if (stack.Count != 0)
  45.                         {
  46.                             Console.WriteLine($"{string.Join(", ",stack)}");
  47.                         }
  48.                         break;
  49.                     case "End":
  50.                         if (queue.Count != 0)
  51.                         {
  52.                             Console.WriteLine($"Vehicles for service: {string.Join(", ", queue)}");
  53.                         }
  54.                         Console.WriteLine($"Served vehicles: {string.Join(", ", stack)}");
  55.                         return;
  56.                     default:
  57.                         break;
  58.                 }
  59.  
  60.             }
  61.  
  62.            
  63.  
  64.            
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement