petarkobakov

The Garden

Oct 25th, 2020 (edited)
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. using System;
  2. using System.ComponentModel.DataAnnotations.Schema;
  3. using System.Linq;
  4.  
  5. namespace Garden
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int[] dimensionsInput = Console.ReadLine().Split().Select(int.Parse).ToArray();
  12. int rows = dimensionsInput[0];
  13. int cols = dimensionsInput[1];
  14.  
  15. int[,] garden = new int[rows, cols];
  16.  
  17.  
  18.  
  19. string command = Console.ReadLine();
  20.  
  21. while (command != "Bloom Bloom Plow")
  22. {
  23. int[] blooming = command.Split().Select(int.Parse).ToArray();
  24.  
  25. int currentRow = blooming[0];
  26. int currentCol = blooming[1];
  27.  
  28. if ((currentRow < 0 || currentRow > rows - 1)
  29. || (currentCol < 0 || currentCol > cols - 1))
  30. {
  31. Console.WriteLine("Invalid coordinates.");
  32. continue;
  33. }
  34.  
  35. garden[currentRow, currentCol] = 1;
  36.  
  37. for (int col = 0; col < cols; col++)
  38. {
  39. if (garden[currentRow, col] == 1)
  40. {
  41. garden[currentRow, col] = 2;
  42. }
  43.  
  44. else
  45. {
  46. garden[currentRow, col] = 1;
  47. }
  48.  
  49.  
  50. }
  51.  
  52. for (int row = 0; row < rows; row++)
  53. {
  54. if (garden[row, currentCol] == 1)
  55. {
  56. garden[row, currentCol] = 2;
  57. }
  58. else
  59. {
  60. garden[row, currentCol] = 1;
  61. }
  62.  
  63.  
  64. }
  65.  
  66. command = Console.ReadLine();
  67. }
  68.  
  69. PrintGarden(rows, cols, garden);
  70. }
  71.  
  72. private static void PrintGarden(int rows, int cols, int[,] garden)
  73. {
  74. for (int row = 0; row < rows; row++)
  75. {
  76. for (int col = 0; col < cols; col++)
  77. {
  78. Console.Write(garden[row, col] + " ");
  79. }
  80. Console.WriteLine();
  81. }
  82. }
  83. }
  84. }
  85.  
Advertisement
Add Comment
Please, Sign In to add comment