Advertisement
Prohause

Jedi Galaxy

Jun 22nd, 2017
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Jedi_Galaxy
  8. {
  9. public class StartUp
  10. {
  11. public static void Main(string[] args)
  12. {
  13. var dimensions = Console.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)
  14. .Select(int.Parse).ToArray();
  15.  
  16. var galaxy = CreateGalaxy(dimensions);
  17. var input = Console.ReadLine();
  18. var collectedStars = 0L;
  19.  
  20. while (!input.Equals("Let the Force be with you"))
  21. {
  22. var coordinatesIvo = input.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)
  23. .Select(int.Parse).ToArray();
  24.  
  25. input = Console.ReadLine();
  26.  
  27. var coordinatesEvil = input.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)
  28. .Select(int.Parse).ToArray();
  29. DestroyStars(galaxy, coordinatesEvil);
  30. collectedStars += CollectStars(galaxy, coordinatesIvo);
  31.  
  32. input = Console.ReadLine();
  33. }
  34. Console.WriteLine(collectedStars);
  35.  
  36. }
  37.  
  38. private static long CollectStars(int[][] galaxy, int[] coordinatesIvo)
  39. {
  40. var collected = 0L;
  41. var ivoRow = coordinatesIvo[0];
  42. var ivoCol = coordinatesIvo[1];
  43.  
  44. for (int i = ivoRow, j = ivoCol; i >= 0 && j < galaxy[0].Length; i--, j++)
  45. {
  46. if (i < galaxy.Length && j >= 0)
  47. {
  48. collected += galaxy[i][j];
  49. }
  50. }
  51. return collected;
  52.  
  53. }
  54.  
  55. private static void DestroyStars(int[][] galaxy, int[] coordinates)
  56. {
  57. var evilStartRow = coordinates[0];
  58. var evilStartCol = coordinates[1];
  59.  
  60. for (int i = evilStartRow, j = evilStartCol; i >= 0 && j >= 0; i--, j--)
  61. {
  62. if (i < galaxy.Length && j < galaxy[0].Length)
  63. {
  64. galaxy[i][j] = 0;
  65. }
  66. }
  67. }
  68.  
  69. private static int[][] CreateGalaxy(int[] dimensions)
  70. {
  71. var row = dimensions[0];
  72. var col = dimensions[1];
  73. var matrix = new int[row][];
  74.  
  75. for (var i = 0; i < row; i++)
  76. {
  77. matrix[i] = new int[col];
  78.  
  79. for (var j = 0; j < col; j++)
  80. {
  81. matrix[i][j] = i * col + j;
  82. }
  83. }
  84. return matrix;
  85. }
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement