fight90

6. Traffic Light

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