Guest User

Heart Delivery

a guest
Jul 11th, 2020
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Heart_Delivery
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. int[] neighborhood = Console.ReadLine().Split("@").Select(int.Parse).ToArray();
  11. string command = Console.ReadLine();
  12.  
  13. int lastPosition = 0;
  14.  
  15. while (command != "Love!")
  16. {
  17. string[] receivedCommand = command.Split();
  18. int index = int.Parse(receivedCommand[1]);
  19.  
  20. if (lastPosition + index < neighborhood.Length)
  21. {
  22. if (lastPosition + index == 0)
  23. {
  24. Console.WriteLine($"Place {lastPosition + index} already had Valentine's day.");
  25. }
  26.  
  27. else
  28. {
  29. neighborhood[lastPosition + index] -= 2;
  30.  
  31. if (neighborhood[lastPosition + index] == 0)
  32. {
  33. Console.WriteLine($"Place {lastPosition + index} has Valentine's day.");
  34. }
  35.  
  36. lastPosition += index;
  37. }
  38. }
  39.  
  40. else
  41. {
  42. if (neighborhood[0] == 0)
  43. {
  44. Console.WriteLine($"Place 0 already had Valentine's day.");
  45. }
  46. else
  47. {
  48. neighborhood[0] -= 2;
  49. lastPosition = 0;
  50.  
  51. if (neighborhood[0] == 0)
  52. {
  53. Console.WriteLine($"Place 0 has Valentine's day.");
  54. }
  55. }
  56. }
  57.  
  58. command = Console.ReadLine();
  59. }
  60.  
  61. if (command == "Love!")
  62. {
  63. Console.WriteLine($"Cupid's last position was {lastPosition}.");
  64.  
  65. if (neighborhood.Sum() == 0)
  66. {
  67. Console.WriteLine($"Mission was successful.");
  68. }
  69.  
  70. else
  71. {
  72. int houseCount = 0;
  73.  
  74. for (int i = 0; i < neighborhood.Length; i++)
  75. {
  76. if (neighborhood[i] != 0)
  77. {
  78. houseCount++;
  79. }
  80. }
  81. Console.WriteLine($"Cupid has failed {houseCount} places.");
  82. }
  83. }
  84. }
  85. }
  86. }
Add Comment
Please, Sign In to add comment