Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.67 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace PresentDelivery
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. int inputPresent = int.Parse(Console.ReadLine());
  11. int rowAndCol = int.Parse(Console.ReadLine());
  12. int curentPresent = 0;
  13.  
  14. var matrix = new char[rowAndCol, rowAndCol];
  15. int santaRow = 0;
  16. int santaCol = 0;
  17. int allNiceKids = 0;
  18. FillMatrixAndFindSantaAndNiceKids(rowAndCol, matrix, ref santaRow, ref santaCol, ref allNiceKids);
  19.  
  20.  
  21. string command = Console.ReadLine();
  22.  
  23. while (command != "Christmas morning" && curentPresent < inputPresent)
  24. {
  25. // Move Santa
  26. switch (command)
  27. {
  28. case "up": santaRow--; break;
  29. case "down": santaRow++; break;
  30. case "left": santaCol--; break;
  31. case "right": santaCol++; break;
  32. }
  33.  
  34. // Action depending symbol
  35. if (matrix[santaRow, santaCol] == 'V')
  36. {
  37. matrix[santaRow, santaCol] = '-';
  38. curentPresent++;
  39.  
  40. }
  41. else if (matrix[santaRow, santaCol] == 'C')
  42. {
  43. matrix[santaRow, santaCol] = '-';
  44.  
  45.  
  46. if (matrix[santaRow, santaCol - 1] != '-')
  47. {
  48. matrix[santaRow, santaCol - 1] = '-';
  49. curentPresent++;
  50. }
  51. if (matrix[santaRow, santaCol + 1] != '-')
  52. {
  53. matrix[santaRow, santaCol + 1] = '-';
  54. curentPresent++;
  55. }
  56. if (matrix[santaRow - 1, santaCol] != '-')
  57. {
  58. matrix[santaRow - 1, santaCol] = '-';
  59. curentPresent++;
  60. }
  61. if (matrix[santaRow + 1, santaCol] != '-')
  62. {
  63. matrix[santaRow + 1, santaCol] = '-';
  64. curentPresent++;
  65. }
  66. }
  67. else
  68. {
  69. matrix[santaRow, santaCol] = '-';
  70. }
  71.  
  72. command = Console.ReadLine();
  73. }
  74.  
  75.  
  76. matrix[santaRow, santaCol] = 'S';
  77.  
  78.  
  79.  
  80. if (command != "Christmas morning" && curentPresent == inputPresent)
  81. {
  82. Console.WriteLine("Santa ran out of presents!");
  83. }
  84.  
  85. PrintMatrix(rowAndCol, matrix);
  86.  
  87. //Check for children without gifts
  88. var checkForLeftNiceKid = 0;
  89. for (int row = 0; row < rowAndCol; row++)
  90. {
  91. for (int col = 0; col < rowAndCol; col++)
  92. {
  93. if (matrix[row, col] == 'V')
  94. {
  95. checkForLeftNiceKid++;
  96. }
  97. }
  98. }
  99.  
  100. if(checkForLeftNiceKid == 0)
  101. {
  102. Console.WriteLine($"Good job, Santa! {allNiceKids} happy nice kid/s.");
  103. }
  104. else
  105. {
  106. Console.WriteLine($"No presents for {checkForLeftNiceKid} nice kid/s.");
  107. }
  108.  
  109. }
  110.  
  111. private static void PrintMatrix(int rowAndCol, char[,] matrix)
  112. {
  113. for (int row = 0; row < rowAndCol; row++)
  114. {
  115. for (int col = 0; col < rowAndCol; col++)
  116. {
  117. Console.Write(matrix[row, col] + " ");
  118. }
  119. Console.WriteLine();
  120. }
  121. }
  122.  
  123.  
  124. private static void FillMatrixAndFindSantaAndNiceKids(int rowAndCol, char[,] matrix, ref int santaRow, ref int santaCol, ref int allNiceKids)
  125. {
  126. for (int row = 0; row < rowAndCol; row++)
  127. {
  128. var input = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(char.Parse).ToArray();
  129. for (int col = 0; col < rowAndCol; col++)
  130. {
  131. matrix[row, col] = input[col];
  132. if (input[col] == 'S')
  133. {
  134. santaRow = row;
  135. santaCol = col;
  136. matrix[row, col] = '-';
  137. }
  138. if (input[col] == 'V')
  139. {
  140. allNiceKids++;
  141. }
  142. }
  143. }
  144. }
  145. }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement