bullit3189

Present Delivery TF-MidExam 18Dec18

Jan 26th, 2019
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. using System.Collections.Generic;
  4.  
  5. namespace _03PresentDelivery
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string initialHouses = Console.ReadLine();
  12. List<int> houses = initialHouses.Split('@').Select(int.Parse).ToList();
  13.  
  14. int totalHouses = houses.Count;
  15. int totalIndexes = houses.Count - 1;
  16. int housesToDeliver = houses.Count;
  17. int finalIndex = 0;
  18.  
  19. while (true)
  20. {
  21. string command = Console.ReadLine();
  22.  
  23. if (command == "Merry Xmas!")
  24. {
  25. break;
  26. }
  27.  
  28. string[] tokens = command.Split();
  29. string action = tokens[0];
  30.  
  31. if (action == "Jump")
  32. {
  33. int jumpLen = int.Parse(tokens[1]);
  34. finalIndex += jumpLen;
  35.  
  36. if (finalIndex>totalIndexes)
  37. {
  38. finalIndex = finalIndex % totalHouses;
  39. }
  40.  
  41. houses[finalIndex] -= 2;
  42.  
  43. if (houses[finalIndex]==0)
  44. {
  45. housesToDeliver--;
  46. }
  47.  
  48. if (houses[finalIndex]<0 && houses[finalIndex]>=-2)
  49. {
  50. Console.WriteLine($"House {finalIndex} will have a Merry Christmas.");
  51.  
  52. continue;
  53. }
  54.  
  55.  
  56.  
  57. }
  58.  
  59. }
  60.  
  61. Console.WriteLine($"Santa's last position was {finalIndex}.");
  62.  
  63. if (houses.Sum()<=0)
  64. {
  65. Console.WriteLine("Mission was successful.");
  66. }
  67. else
  68. {
  69. Console.WriteLine($"Santa has failed {housesToDeliver} houses.");
  70. }
  71. }
  72. }
  73. }
Add Comment
Please, Sign In to add comment