Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _6._Jagged_Array_Manipulator
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- double[][] jagged = new double[n][];
- for (int i = 0; i < n; i++)
- {
- jagged[i] = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).Select(double.Parse).ToArray();
- }
- for (int row = 0; row < n - 1; row++)
- {
- if (jagged[row].Length == jagged[row + 1].Length)
- {
- for (int j = 0; j < jagged[row].Length; j++)
- {
- jagged[row][j] *= 2;
- jagged[row + 1][j] *= 2;
- }
- }
- else
- {
- for (int j = 0; j < jagged[row].Length; j++)
- {
- jagged[row][j] /= 2;
- }
- for (int j = 0; j < jagged[row + 1].Length; j++)
- {
- jagged[row + 1][j] /= 2;
- }
- }
- }
- while (true)
- {
- string command = Console.ReadLine();
- if (command == "End")
- {
- break;
- }
- string[] data = command.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();
- string action = data[0];
- int rowIndex = int.Parse(data[1]);
- int colIndex = int.Parse(data[2]);
- int value = int.Parse(data[3]);
- if (action == "Add")
- {
- if (rowIndex >= 0 && rowIndex < jagged.Length && colIndex >= 0 && colIndex < jagged[rowIndex].Length)
- {
- jagged[rowIndex][colIndex] += value;
- }
- }
- else if (action == "Subtract")
- {
- if (rowIndex >= 0 && rowIndex < jagged.Length && colIndex >= 0 && colIndex < jagged[rowIndex].Length)
- {
- jagged[rowIndex][colIndex] -= value;
- }
- }
- }
- PrintJaggedArray(jagged);
- }
- private static void PrintJaggedArray(double[][] jagged)
- {
- for (int i = 0; i < jagged.Length; i++)
- {
- for (int j = 0; j < jagged[i].Length; j++)
- {
- Console.Write(jagged[i][j] + " ");
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement