This repository was archived by the owner on Mar 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
47 lines (43 loc) · 1.44 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Linq;
namespace _6._Jagged_Array_Modification
{
internal class Program
{
static void Main(string[] args)
{
int rows = int.Parse(Console.ReadLine());
int[][] jaggedArray = new int[rows][];
for (int row = 0; row < rows; row++)
{
int[] col = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();
jaggedArray[row] = col;
}
string command = Console.ReadLine();
while (command != "END")
{
string[] input = command.Split(" ");
int row = int.Parse(input[1]);
int col = int.Parse(input[2]);
int value = int.Parse(input[3]);
if (row < 0 || col < 0 || row >= jaggedArray.Length || col >= jaggedArray[row].Length)
{
Console.WriteLine("Invalid coordinates");
}
else if (input[0] == "Add")
{
jaggedArray[row][col] += value;
}
else if (input[0] == "Subtract")
{
jaggedArray[row][col] -= value;
}
command = Console.ReadLine();
}
for (int i = 0; i < jaggedArray.Length; i++)
{
Console.WriteLine($"{string.Join(" ", jaggedArray[i])}");
}
}
}
}