silvana1303

traffic jam

Sep 19th, 2020
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace advanced
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int n = int.Parse(Console.ReadLine());
  12.             Queue<string> queue = new Queue<string>();
  13.  
  14.             int count = 0;
  15.             string command = Console.ReadLine();
  16.  
  17.             while (command != "end")
  18.             {
  19.                 if (command == "green")
  20.                 {
  21.                     for (int i = 0; i < n; i++)
  22.                     {
  23.                        
  24.                         if (queue.Count == 0)
  25.                         {
  26.                             break;
  27.                         }
  28.                         Console.WriteLine($"{queue.Dequeue()} passed!");
  29.                         count++;
  30.                     }
  31.                 }
  32.                 else
  33.                 {
  34.                     queue.Enqueue(command);
  35.                 }
  36.  
  37.                 command = Console.ReadLine();
  38.             }
  39.  
  40.             Console.WriteLine($"{count} cars passed the crossroads.");
  41.            
  42.         }
  43.     }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment