Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Crossroads
  6. {
  7. class Crossroads
  8. {
  9. static void Main()
  10. {
  11. int sec = int.Parse(Console.ReadLine());
  12. int bonus = int.Parse(Console.ReadLine());
  13.  
  14. string line = string.Empty;
  15.  
  16. Queue<string> queue = new Queue<string>();
  17.  
  18. int countPassed = 0;
  19.  
  20. while ((line = Console.ReadLine()) != "END")
  21. {
  22. if (line == "green")
  23. {
  24. int temp = sec;
  25.  
  26. while (queue.Any())
  27. {
  28. var carName = queue.Dequeue();
  29. if (temp - carName.Length >= 0)
  30. {
  31. temp -= carName.Length;
  32. countPassed++;
  33. if (queue.Count == 0 || temp == 0)
  34. {
  35. break;
  36. }
  37. }
  38. else if ((temp + bonus) - carName.Length >= 0)
  39. {
  40. countPassed++;
  41. break;
  42. }
  43. else
  44. {
  45. Console.WriteLine("A crash happened!");
  46. Console.WriteLine($"{carName} was hit at {carName.Substring(temp + bonus, 1)}.");
  47. return;
  48. }
  49. }
  50. }
  51. else
  52. {
  53. queue.Enqueue(line);
  54. }
  55. }
  56. Console.WriteLine("Everyone is safe.");
  57. Console.WriteLine($"{countPassed} total cars passed the crossroads.");
  58. }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement