Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Advance
- {
- class Program
- {
- static void Main(string[] args)
- {
- int totalCars = 0;
- int greenLightSeconds = int.Parse(Console.ReadLine());
- int totalgreenLightSeconds = greenLightSeconds;
- int freeWindow = int.Parse(Console.ReadLine());
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "END")
- {
- break;
- }
- else if (input == "green")
- {
- greenLightSeconds = totalgreenLightSeconds;
- continue;
- }
- if (greenLightSeconds == 0)
- {
- continue;
- }
- int CarsLenght = input.Length;
- if (CarsLenght <= greenLightSeconds)
- {
- greenLightSeconds = greenLightSeconds - CarsLenght;
- }
- else
- {
- if (greenLightSeconds + freeWindow >= CarsLenght)
- {
- greenLightSeconds = 0;
- }
- else
- {
- int indexoFcrash = greenLightSeconds + freeWindow;
- Console.WriteLine("A crash happened!");
- Console.WriteLine($"{input} was hit at {input[indexoFcrash]}.");
- return;
- }
- }
- totalCars++;
- }
- Console.WriteLine($"Everyone is safe.");
- Console.WriteLine($"{totalCars} total cars passed the crossroads.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement