Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.06 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. public class Colecting
  4. {
  5. static void Main()
  6. {
  7. string galaxyData = Console.ReadLine();
  8. int[] dimestions = galaxyData
  9. .Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)
  10. .Select(int.Parse)
  11. .ToArray();
  12.  
  13. int row = dimestions[0];
  14. int col = dimestions[1];
  15.  
  16. Space galaxy = new Space(dimestions[0], dimestions[1]);
  17.  
  18. Console.WriteLine(ColectingHearths(galaxy));
  19. }
  20.  
  21. private static string ColectingHearths(Space galaxy)
  22. {
  23. string loverData;
  24. long sum = 0L;
  25.  
  26. Coordinates coordinates = new Coordinates();
  27. Evil evil = new Evil();
  28. Lover ivo = new Lover(sum);
  29.  
  30. while ((loverData = Console.ReadLine()) != "Let the Force be with you")
  31. {
  32. evil = new Evil(new Coordinates(Console.ReadLine()));
  33. evil.RemoveStars(galaxy.Matrix);
  34.  
  35. ivo = new Lover(new Coordinates(loverData));
  36. ivo.ColectingStars(galaxy.Matrix, ivo.StarsColected);
  37. }
  38. return ivo.StarsColected.ToString();
  39. }
  40. }
  41.  
  42. using System;
  43. using System.Collections.Generic;
  44. using System.Text;
  45.  
  46. public class Space
  47. {
  48. int[,] matrix;
  49.  
  50. public int[,] Matrix { get => matrix; set => matrix = value; }
  51.  
  52. public Space(int rowCount, int colCount)
  53. {
  54. int value = 0;
  55.  
  56. matrix = new int[rowCount, colCount];
  57.  
  58. for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
  59. {
  60. for (int colIndex = 0; colIndex < colCount; colIndex++)
  61. {
  62. matrix[rowIndex, colIndex] = value++;
  63. }
  64. }
  65. Matrix = matrix;
  66. }
  67. }
  68.  
  69. using System;
  70. using System.Collections.Generic;
  71. using System.Text;
  72. public class Evil
  73. {
  74. Coordinates location;
  75. Coordinates Location { get => location; set => location = value; }
  76.  
  77. public Evil()
  78. {
  79. Location = location;
  80. }
  81.  
  82. public Evil(Coordinates loc)
  83. {
  84. Location = loc;
  85. }
  86.  
  87. public int[,] RemoveStars(int [,] matrix)
  88. {
  89.  
  90. while (Location.Row >= 0 && Location.Col >= 0)
  91. {
  92. if (Location.Row >= 0 && Location.Row < matrix.GetLength(0) && Location.Col >= 0 && Location.Col < matrix.GetLength(1))
  93. {
  94. matrix[Location.Row, Location.Col] = 0;
  95. }
  96. Location.Row--;
  97. Location.Col--;
  98. }
  99.  
  100. return matrix;
  101. }
  102. }
  103.  
  104. using System;
  105. using System.Collections.Generic;
  106. using System.Linq;
  107. using System.Text;
  108.  
  109. public class Coordinates
  110. {
  111. int row;
  112. int col;
  113.  
  114. public int Row { get => row; set => row = value; }
  115. public int Col { get => col; set => col = value; }
  116. public Coordinates()
  117. {
  118. Row = row;
  119. Col = col;
  120. }
  121. public Coordinates(string input)
  122. {
  123. int[] evilLocation = input
  124. .Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)
  125. .Select(int.Parse).ToArray();
  126.  
  127. Row = evilLocation[0];
  128. Col = evilLocation[1];
  129. }
  130. }
  131. using System;
  132. using System.Collections.Generic;
  133. using System.Text;
  134. public class Lover
  135. {
  136. Coordinates location;
  137. long starsColected;
  138.  
  139. public long StarsColected { get => starsColected; set => starsColected = value; }
  140. internal Coordinates Location { get => location; set => location = value; }
  141.  
  142. public Lover(long stars)
  143. {
  144. Location = location;
  145. StarsColected = stars;
  146. }
  147. public Lover(Coordinates loc)
  148. {
  149. Location = loc;
  150. }
  151. public void ColectingStars(int [,] matrix, long sum)
  152. {
  153.  
  154. while (Location.Row >= 0 && Location.Col < matrix.GetLength(1))
  155. {
  156. if (Location.Row >= 0 && Location.Row < matrix.GetLength(0) && Location.Col >= 0 && Location.Col < matrix.GetLength(1))
  157. {
  158. sum += matrix[Location.Row, Location.Col];
  159. }
  160.  
  161. Location.Col++;
  162. Location.Row--;
  163. }
  164.  
  165. StarsColected = sum;
  166. }
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement