GabrielDas

Untitled

Mar 9th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace P03PresentDelivery
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<string> houses = Console.ReadLine().Split('@').ToList();
  12. List<int> membersInHouses = new List<int>();
  13.  
  14. for (int i = 0; i < houses.Count; i++)
  15. {
  16. int members = int.Parse(houses[i]);
  17. membersInHouses.Add(members);
  18. }
  19.  
  20. int lastPos = 0;
  21.  
  22. while (true)
  23. {
  24. string command = Console.ReadLine();
  25. string[] tokens = command.Split();
  26.  
  27. if (command == "Merry Xmas!")
  28. {
  29. break;
  30. }
  31. else if (tokens[0]=="Jump")
  32. {
  33. int length = int.Parse(tokens[1])+ lastPos;
  34.  
  35.  
  36. if(length > membersInHouses.Count - 1)
  37. {
  38. if (length % membersInHouses.Count == 0)
  39. {
  40. length = 0;
  41.  
  42. }
  43. else
  44. {
  45. length = length % membersInHouses.Count;
  46. Console.WriteLine(length);
  47. }
  48. }
  49.  
  50. for(int j = 0; j < membersInHouses.Count; j++)
  51. {
  52. if (j == length)
  53. {
  54. lastPos = j;
  55. }
  56. }
  57.  
  58.  
  59. Jump(membersInHouses, length);
  60.  
  61.  
  62. }
  63. }
  64.  
  65. int countOfHousesWithPresent = 0;
  66.  
  67. for(int j = 0; j < membersInHouses.Count; j++)
  68. {
  69. if(membersInHouses[j] > 0)
  70. {
  71. countOfHousesWithPresent ++;
  72. }
  73. }
  74.  
  75. Console.WriteLine($"Santa's last position was {lastPos}.");
  76.  
  77.  
  78. if (membersInHouses.Sum()==0)
  79. {
  80. Console.WriteLine( "Mission was successful.");
  81. }
  82. else
  83. {
  84. Console.WriteLine($"Santa has failed {countOfHousesWithPresent} houses.");
  85. }
  86.  
  87. }
  88.  
  89. private static void Jump(List<int> membersInHouses, int length)
  90. {
  91. if (membersInHouses[length]==0)
  92. {
  93. int index = 0;
  94.  
  95. for (int k = 0; k < membersInHouses.Count; k++)
  96. {
  97. if (k == length)
  98. {
  99. index = k;
  100. }
  101.  
  102. }
  103. Console.WriteLine($"House {index} will have a Merry Christmas.");
  104. return;
  105. }
  106. else
  107. {
  108. membersInHouses[length] = membersInHouses[length] - 2;
  109. }
  110. }
  111. }
  112. }
Add Comment
Please, Sign In to add comment