Advertisement
Guest User

Untitled

a guest
Sep 17th, 2021
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace JaggedArrayModification
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. int rowsLength = int.Parse(Console.ReadLine());
  11.  
  12. int[][] jaggedArray = new int[rowsLength][];
  13.  
  14. for (int row = 0; row < jaggedArray.Length; row++)
  15. {
  16. int[] elements = Console.ReadLine().Split().Select(int.Parse).ToArray();
  17. jaggedArray[row] = new int[elements.Length];
  18.  
  19. for (int col = 0; col < jaggedArray[row].Length; col++)
  20. {
  21. jaggedArray[row][col] = elements[col];
  22. }
  23. }
  24.  
  25. string[] command = Console.ReadLine().Split();
  26.  
  27. while (command[0] != "END")
  28. {
  29. int row = 0;
  30. int col = 0;
  31. int value = 0;
  32.  
  33. for (int i = 0; i < jaggedArray.Length; i++)
  34. {
  35. row = int.Parse(command[1]);
  36. col = int.Parse(command[2]);
  37. value = int.Parse(command[3]);
  38.  
  39. if (row < 0 || row >= jaggedArray.Length || col < 0 || col >= jaggedArray[i].Length)
  40. {
  41. Console.WriteLine("Invalid coordinates");
  42. command = Console.ReadLine().Split();
  43. i--;
  44. continue;
  45. }
  46. }
  47.  
  48. if (command[0] == "Add")
  49. {
  50. jaggedArray[row][col] += value;
  51. }
  52. else if (command[0] == "Subtract")
  53. {
  54. jaggedArray[row][col] -= value;
  55. }
  56.  
  57. command = Console.ReadLine().Split();
  58. }
  59.  
  60. for (int row = 0; row < jaggedArray.Length; row++)
  61. {
  62. Console.WriteLine(String.Join(" ", jaggedArray[row]));
  63. }
  64. }
  65. }
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement