Advertisement
bullit3189

Crossroads

Jun 13th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using System.Numerics;
  6.  
  7. public class Program
  8. {
  9. public static void Main()
  10. {
  11. int greenLight = int.Parse(Console.ReadLine());
  12.  
  13. int greenCopy = greenLight;
  14. int yellow = int.Parse(Console.ReadLine());
  15.  
  16. Queue<string> cars = new Queue<string>();
  17.  
  18. int passed = 0;
  19.  
  20. while(true)
  21. {
  22. string command = Console.ReadLine();
  23.  
  24. if(command == "END")
  25. {
  26. break;
  27. }
  28.  
  29. if(command!="green")
  30. {
  31. cars.Enqueue(command);
  32. greenLight = greenCopy;
  33. }
  34. else if (command == "green")
  35. {
  36. while(cars.Any())
  37. {
  38. string currCar = cars.Peek();
  39. int currLen = currCar.Length;
  40.  
  41. if(currLen<=greenLight)
  42. {
  43. greenLight-=currLen;
  44. cars.Dequeue();
  45. passed++;
  46.  
  47. if(greenLight==0)
  48. {
  49. greenLight = greenCopy;
  50. break;
  51. }
  52. }
  53. else
  54. {
  55. if(currLen<=greenLight+yellow)
  56. {
  57. cars.Dequeue();
  58. passed++;
  59. break;
  60. }
  61. else
  62. {
  63. Console.WriteLine("A crash happened!");
  64. Console.WriteLine("{0} was hit at {1}.",currCar,currCar[greenLight+yellow]);
  65. return;
  66. }
  67. }
  68. }
  69. }
  70. }
  71.  
  72. Console.WriteLine("Everyone is safe.");
  73. Console.WriteLine("{0} total cars passed the crossroads.",passed);
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement