PetarNeshkov5360

02. Garden

Jan 27th, 2021
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Garden
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. int[] dimensions = Console.ReadLine().Split().Select(int.Parse).ToArray();
  11. int row = dimensions[0];
  12. int col = dimensions[1];
  13. int[,] matrix = new int[row, col];
  14. string input;
  15. while ((input = Console.ReadLine()) != "Bloom Bloom Plow")
  16. {
  17. int[] numbers = input.Split().Select(int.Parse).ToArray();
  18. int currRow = numbers[0];
  19. int currCol = numbers[1];
  20.  
  21. int rowToChange = currRow;
  22. int colToChange = currCol;
  23. if (Check(row,col,currRow,currCol))
  24. {
  25. while (rowToChange>=0) //up
  26. {
  27. matrix[rowToChange, colToChange]++;
  28. rowToChange--;
  29. }
  30. rowToChange = currRow+1;
  31. while (rowToChange<row) //down
  32. {
  33. matrix[rowToChange, colToChange]++;
  34. rowToChange++;
  35. }
  36. rowToChange = currRow;
  37. colToChange--;
  38. while (colToChange>=0)//left
  39. {
  40. matrix[rowToChange, colToChange]++;
  41. colToChange--;
  42. }
  43. colToChange = currCol+1;
  44. while (colToChange<col)//right
  45. {
  46. matrix[rowToChange, colToChange]++;
  47. colToChange++;
  48. }
  49. }
  50. else
  51. {
  52. Console.WriteLine("Invalid coordinates");
  53. }
  54. }
  55. PrintMatrix(matrix);
  56. }
  57. public static void PrintMatrix(int[,] matrix)
  58. {
  59. for (int row = 0; row < matrix.GetLength(0); row++)
  60. {
  61. for (int col = 0; col < matrix.GetLength(1); col++)
  62. {
  63. Console.Write(matrix[row, col]+" ");
  64. }
  65. Console.WriteLine();
  66. }
  67. }
  68. public static bool Check(int row, int col, int initialRow, int initialCol)
  69. {
  70. if ((initialRow >= 0 && initialRow < row) && (initialCol >= 0 && initialCol < col))
  71. {
  72. return true;
  73. }
  74. return false;
  75. }
  76. }
  77. }
  78.  
Advertisement
Add Comment
Please, Sign In to add comment