Advertisement
VickSuna

Untitled

Sep 5th, 2021
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _6._Jagged_Array_Manipulator
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. int n = int.Parse(Console.ReadLine());
  11. double[][] jagged = new double[n][];
  12. for (int i = 0; i < n; i++)
  13. {
  14. jagged[i] = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).Select(double.Parse).ToArray();
  15. }
  16. for (int row = 0; row < n - 1; row++)
  17. {
  18. if (jagged[row].Length == jagged[row + 1].Length)
  19. {
  20. for (int j = 0; j < jagged[row].Length; j++)
  21. {
  22. jagged[row][j] *= 2;
  23. jagged[row + 1][j] *= 2;
  24. }
  25.  
  26. }
  27. else
  28. {
  29. for (int j = 0; j < jagged[row].Length; j++)
  30. {
  31. jagged[row][j] /= 2;
  32.  
  33. }
  34. for (int j = 0; j < jagged[row + 1].Length; j++)
  35. {
  36. jagged[row + 1][j] /= 2;
  37. }
  38.  
  39.  
  40.  
  41. }
  42. }
  43. while (true)
  44. {
  45. string command = Console.ReadLine();
  46. if (command == "End")
  47. {
  48.  
  49. break;
  50. }
  51. string[] data = command.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();
  52. string action = data[0];
  53. int rowIndex = int.Parse(data[1]);
  54. int colIndex = int.Parse(data[2]);
  55. int value = int.Parse(data[3]);
  56. if (action == "Add")
  57. {
  58. if (rowIndex >= 0 && rowIndex < jagged.Length && colIndex >= 0 && colIndex < jagged[rowIndex].Length)
  59. {
  60. jagged[rowIndex][colIndex] += value;
  61. }
  62.  
  63.  
  64. }
  65. else if (action == "Subtract")
  66. {
  67.  
  68. if (rowIndex >= 0 && rowIndex < jagged.Length && colIndex >= 0 && colIndex < jagged[rowIndex].Length)
  69. {
  70. jagged[rowIndex][colIndex] -= value;
  71. }
  72. }
  73. }
  74. PrintJaggedArray(jagged);
  75.  
  76.  
  77. }
  78.  
  79. private static void PrintJaggedArray(double[][] jagged)
  80. {
  81. for (int i = 0; i < jagged.Length; i++)
  82. {
  83. for (int j = 0; j < jagged[i].Length; j++)
  84. {
  85. Console.Write(jagged[i][j] + " ");
  86. }
  87. Console.WriteLine();
  88. }
  89. }
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement