Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. namespace _2.Jedi_Galaxy
  2. {
  3. using System;
  4. using System.Linq;
  5. class Program
  6. {
  7. static void Main()
  8. {
  9. var dimensions = Console.ReadLine().Split().Select(int.Parse).ToArray();
  10. var matrixRows = dimensions[0];
  11. var matrixCols = dimensions[1];
  12. var galaxy = new long[matrixRows][];
  13. long stars = 0;
  14. for (int i = 0; i < galaxy.Length; i++)
  15. {
  16. galaxy[i]= new long[matrixCols];
  17. for (int j = 0; j < galaxy[i].Length; j++)
  18. {
  19. galaxy[i][j] = stars;
  20. stars++;
  21. }
  22. }
  23. var ivoCordinates = Console.ReadLine();
  24. int ivoRow = ivoCordinates[0];
  25. int ivoCol = ivoCordinates[1];
  26. long starsCollected = 0;
  27. var evilForces = Console.ReadLine();
  28. while (evilForces!= "Let the Force be with you" || ivoCordinates!= "Let the Force be with you")
  29. {
  30. var ivoTokens = ivoCordinates.Split().Select(int.Parse).ToArray();
  31. ivoRow = ivoTokens[0];
  32. ivoCol = ivoTokens[1];
  33.  
  34. var evilForcesCord = evilForces.Split().Select(int.Parse).ToArray();
  35. var evilForcesRow = evilForcesCord[0];
  36. var evilForcesCol = evilForcesCord[1];
  37.  
  38. EvilForcesContributeToGalaxy(galaxy, evilForcesRow, evilForcesCol, matrixRows,matrixCols);
  39. starsCollected= IvoCollectingStars(galaxy, ivoRow, ivoCol, matrixRows, matrixCols);
  40. ivoCordinates = Console.ReadLine();
  41. if (ivoCordinates == "Let the Force be with you")
  42. {
  43. break;
  44. }
  45. evilForces = Console.ReadLine();
  46. }
  47.  
  48. Console.WriteLine(starsCollected);
  49. }
  50.  
  51. private static long IvoCollectingStars(long[][] galaxy, int ivoRow, int ivoCol, int matrixRows, int matrixCols)
  52. {
  53. long starsCollected = 0;
  54. while (ivoRow >= 0 && ivoCol < matrixCols)
  55. {
  56. if (IsInMatrix(matrixRows, ivoRow, ivoCol, matrixCols))
  57. {
  58. starsCollected += galaxy[ivoRow][ivoCol];
  59. }
  60. ivoRow--;
  61. ivoCol++;
  62. }
  63.  
  64. return starsCollected;
  65. }
  66.  
  67. private static void EvilForcesContributeToGalaxy(long[][] galaxy, int evilForcesRow, int evilForcesCol, int rows , int cols )
  68. {
  69.  
  70. while (evilForcesRow>=0 && evilForcesCol>=0)
  71. {
  72. if (IsInMatrix(rows,evilForcesRow,evilForcesCol,cols))
  73. {
  74. galaxy[evilForcesRow][evilForcesCol] = 0;
  75. }
  76. evilForcesRow--;
  77. evilForcesCol--;
  78. }
  79.  
  80. }
  81. public static bool IsInMatrix(int row, int testRow, int testCol, int columns)
  82. {
  83. if (testRow >= 0 && testRow < row && testCol >= 0 && testCol < columns)
  84. {
  85. return true;
  86. }
  87. else
  88. {
  89. return false;
  90. }
  91. }
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement