Advertisement
Guest User

Untitled

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