damyan91

Untitled

Jun 20th, 2017
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 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 _02.Nature_s_Prophet
  8. {
  9. public class NaturesProphet
  10. {
  11. public static void Main()
  12. {
  13. int[] sizes = Console.ReadLine().Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries)
  14. .Select(int.Parse)
  15. .ToArray();
  16.  
  17. int[][] matrix = new int[sizes[0]][];
  18.  
  19. for (int row = 0; row < matrix.Length; row++)
  20. {
  21. matrix[row] = new int[sizes[1]];
  22. }
  23.  
  24. string line = Console.ReadLine();
  25.  
  26. while (line != "Bloom Bloom Plow")
  27. {
  28. var tokens = line.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries);
  29. int currentRow = int.Parse(tokens[0]);
  30. int currentCol = int.Parse(tokens[1]);
  31.  
  32. for (int row = currentRow; row <= currentRow; row++)
  33. {
  34. for (int col = currentCol; col < matrix[row].Length; col++)
  35. {
  36. if (IsInRange(matrix, row, col))
  37. {
  38. matrix[row][col]++;
  39. }
  40. }
  41.  
  42. for (int col = currentCol - 1; col >= 0; col--)
  43. {
  44. if (IsInRange(matrix, row, col))
  45. {
  46. matrix[row][col]++;
  47. }
  48. }
  49. }
  50.  
  51.  
  52. for (int col = currentCol; col <= currentCol; col++)
  53. {
  54. for (int row = currentRow + 1; row < matrix.Length; row++)
  55. {
  56. if (IsInRange(matrix, row, col))
  57. {
  58. matrix[row][col]++;
  59. }
  60. }
  61.  
  62. for (int row = currentRow - 1; row >= 0; row--)
  63. {
  64. if (IsInRange(matrix, row, col))
  65. {
  66. matrix[row][col]++;
  67. }
  68. }
  69. }
  70.  
  71.  
  72.  
  73. line = Console.ReadLine();
  74. }
  75.  
  76. for (int row = 0; row < matrix.Length; row++)
  77. {
  78. for (int col = 0; col < matrix[row].Length; col++)
  79. {
  80. Console.Write(matrix[row][col] + " ");
  81. }
  82. Console.WriteLine();
  83. }
  84. }
  85.  
  86. public static bool IsInRange(int[][] matrix, int row, int col)
  87. {
  88. if (row < matrix.Length && col < matrix[row].Length)
  89. {
  90. return true;
  91. }
  92.  
  93. return false;
  94. }
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment