Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace advanced
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- Queue<string> queue = new Queue<string>();
- int count = 0;
- string command = Console.ReadLine();
- while (command != "end")
- {
- if (command == "green")
- {
- for (int i = 0; i < n; i++)
- {
- if (queue.Count == 0)
- {
- break;
- }
- Console.WriteLine($"{queue.Dequeue()} passed!");
- count++;
- }
- }
- else
- {
- queue.Enqueue(command);
- }
- command = Console.ReadLine();
- }
- Console.WriteLine($"{count} cars passed the crossroads.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment