petarkobakov

Heart Delivery

Jul 1st, 2020
92
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.Collections.Generic;
  3. using System.Linq;
  4. using System.Security;
  5.  
  6. namespace HeartDelivery
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. List<int> houses = Console.ReadLine()
  13. .Split("@")
  14. .Select(int.Parse)
  15. .ToList();
  16.  
  17. string input = string.Empty;
  18. int startIndex = 0;
  19. while ((input = Console.ReadLine()) != "Love!")
  20. {
  21. string[] elements = input.Split().ToArray();
  22.  
  23. int length = int.Parse(elements[1]);
  24.  
  25. if (length + startIndex > houses.Count - 1)
  26. {
  27. startIndex = 0;
  28. }
  29. else
  30. {
  31. startIndex = length + startIndex;
  32. }
  33.  
  34. if (houses[startIndex] <= 0)
  35. {
  36. Console.WriteLine($"Place {startIndex} already had Valentine's day.");
  37. }
  38. else
  39. {
  40. houses[startIndex] -= 2;
  41. if (houses[startIndex] <= 0)
  42. {
  43. Console.WriteLine($"Place {startIndex} has Valentine's day.");
  44. }
  45. }
  46.  
  47. }
  48.  
  49. Console.WriteLine($"Cupid's last position was {startIndex}.");
  50. int count = 0;
  51. for (int i = 0; i < houses.Count; i++)
  52. {
  53. if (houses[i] == 0)
  54. {
  55. count++;
  56. }
  57. }
  58. if (count == houses.Count)
  59. {
  60. Console.WriteLine("Mission was successful.");
  61. }
  62. else
  63. {
  64. Console.WriteLine($"Cupid has failed {houses.Count - count} places.");
  65. }
  66. }
  67. }
  68. }
Add Comment
Please, Sign In to add comment