Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text;
- using System.Numerics;
- public class Program
- {
- public static void Main()
- {
- int greenLight = int.Parse(Console.ReadLine());
- int greenCopy = greenLight;
- int yellow = int.Parse(Console.ReadLine());
- Queue<string> cars = new Queue<string>();
- int passed = 0;
- while(true)
- {
- string command = Console.ReadLine();
- if(command == "END")
- {
- break;
- }
- if(command!="green")
- {
- cars.Enqueue(command);
- greenLight = greenCopy;
- }
- else if (command == "green")
- {
- while(cars.Any())
- {
- string currCar = cars.Peek();
- int currLen = currCar.Length;
- if(currLen<=greenLight)
- {
- greenLight-=currLen;
- cars.Dequeue();
- passed++;
- if(greenLight==0)
- {
- greenLight = greenCopy;
- break;
- }
- }
- else
- {
- if(currLen<=greenLight+yellow)
- {
- cars.Dequeue();
- passed++;
- break;
- }
- else
- {
- Console.WriteLine("A crash happened!");
- Console.WriteLine("{0} was hit at {1}.",currCar,currCar[greenLight+yellow]);
- return;
- }
- }
- }
- }
- }
- Console.WriteLine("Everyone is safe.");
- Console.WriteLine("{0} total cars passed the crossroads.",passed);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement