Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _06._Jagged_Array_Manipulator
- {
- class Program
- {
- static void Main(string[] args)
- {
- int numberOfRows = int.Parse(Console.ReadLine());
- double[][] jaggedArray = new double[numberOfRows][];
- for (int row = 0; row < numberOfRows; row++)
- {
- jaggedArray[row] = Console.ReadLine()
- .Split(" ")
- .Select(double.Parse)
- .ToArray();
- }
- for (int row = 0; row < numberOfRows - 1; row++)
- {
- if (jaggedArray[row].Length == jaggedArray[row + 1].Length)
- {
- jaggedArray[row] = jaggedArray[row].Select(x => x * 2).ToArray();
- jaggedArray[row + 1] = jaggedArray[row + 1].Select(x => x * 2).ToArray();
- }
- else
- {
- jaggedArray[row] = jaggedArray[row].Select(x => x / 2).ToArray();
- jaggedArray[row + 1] = jaggedArray[row + 1].Select(x => x / 2).ToArray();
- }
- }
- string input;
- while((input = Console.ReadLine()) != "End")
- {
- string[] commands = input.Split(" ");
- string command = commands[0];
- int row = int.Parse(commands[1]);
- int col = int.Parse(commands[2]);
- double value = double.Parse(commands[3]);
- bool isValid = ValidationRangeMatrix(jaggedArray, row, col);
- if (isValid)
- {
- switch (command)
- {
- case "Add":
- jaggedArray[row][col] += value;
- break;
- case "Subtract":
- jaggedArray[row][col] -= value;
- break;
- }
- }
- }
- for (int row = 0; row < numberOfRows; row++)
- {
- Console.WriteLine(string.Join(" ", jaggedArray[row]));
- }
- }
- private static bool ValidationRangeMatrix(double[][] jaggedArray, int row, int col)
- => row >= 0 && jaggedArray.GetLength(0) > row && col >= 0 && jaggedArray[row].Length > col ?
- true : false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement