Teo_Yanchev

C# Fundamentals - 03. HeathDelviery - 29.02.2020 G2

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