Advertisement
Guest User

Untitled

a guest
Mar 6th, 2019
555
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace PresentDelivery
  6. {
  7. class Program
  8. {
  9. static void Main()
  10. {
  11. List<int> houses = Console.ReadLine()
  12. .Split('@')
  13. .Select(int.Parse)
  14. .ToList();
  15.  
  16. string currentJumpCommand = Console.ReadLine();
  17.  
  18. int lastPosition = 0;
  19. while (currentJumpCommand != "Merry Xmas!")
  20. {
  21. int currLength = int.Parse((currentJumpCommand.Split())[1]);
  22.  
  23. lastPosition += currLength;
  24.  
  25. while (lastPosition >= houses.Count)
  26. {
  27. lastPosition -= houses.Count;
  28. }
  29.  
  30. if (houses[lastPosition] == 0)
  31. {
  32. Console.WriteLine($"House {lastPosition} will have a Merry Christmas.");
  33. }
  34. else if (houses[lastPosition] > 2)
  35. {
  36. houses[lastPosition] -= 2;
  37. }
  38. else
  39. {
  40. houses[lastPosition] = 0;
  41. }
  42. currentJumpCommand = Console.ReadLine();
  43. }
  44.  
  45. Console.WriteLine("Santa's last position was {0}.", lastPosition);
  46.  
  47. bool successfulChristmas = true;
  48. int counter = 0;
  49. foreach (int presents in houses)
  50. {
  51. if (presents > 0)
  52. {
  53. counter += 1;
  54. successfulChristmas = false;
  55. }
  56. }
  57.  
  58. if (successfulChristmas)
  59. {
  60. Console.WriteLine("Mission was successful.");
  61. }
  62. else
  63. {
  64. Console.WriteLine($"Santa has failed {counter} houses.");
  65. }
  66. //if (houses.Max() < 1)
  67. //{
  68. // Console.WriteLine("Mission was successful.");
  69. //}
  70. //else
  71. //{
  72. // int[] count = houses.Where(x => x != 0).ToArray();
  73. // Console.WriteLine($"Santa has failed {count.Count()} houses.");
  74. //}
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement