Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
513
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Advance
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. int totalCars = 0;
  13. int greenLightSeconds = int.Parse(Console.ReadLine());
  14. int totalgreenLightSeconds = greenLightSeconds;
  15. int freeWindow = int.Parse(Console.ReadLine());
  16.  
  17. while (true)
  18. {
  19. string input = Console.ReadLine();
  20. if (input == "END")
  21. {
  22. break;
  23. }
  24. else if (input == "green")
  25. {
  26. greenLightSeconds = totalgreenLightSeconds;
  27.  
  28. continue;
  29. }
  30. if (greenLightSeconds == 0)
  31. {
  32. continue;
  33. }
  34. int CarsLenght = input.Length;
  35. if (CarsLenght <= greenLightSeconds)
  36. {
  37.  
  38. greenLightSeconds = greenLightSeconds - CarsLenght;
  39.  
  40.  
  41.  
  42. }
  43. else
  44. {
  45. if (greenLightSeconds + freeWindow >= CarsLenght)
  46. {
  47. greenLightSeconds = 0;
  48.  
  49.  
  50. }
  51. else
  52. {
  53. int indexoFcrash = greenLightSeconds + freeWindow;
  54. Console.WriteLine("A crash happened!");
  55. Console.WriteLine($"{input} was hit at {input[indexoFcrash]}.");
  56. return;
  57. }
  58.  
  59.  
  60. }
  61.  
  62.  
  63.  
  64. totalCars++;
  65. }
  66.  
  67. Console.WriteLine($"Everyone is safe.");
  68. Console.WriteLine($"{totalCars} total cars passed the crossroads.");
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83. }
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement