Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Text;
- namespace Jagged_Array_Manipulator
- {
- class JaggedArrayManipulator
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- double[][] matrix = new double[n][];
- for (int i = 0; i < n; i++)
- {
- double[] temp = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(double.Parse).ToArray();
- matrix[i] = temp;
- }
- for (int row = 0; row < matrix.Length - 1; row++)
- {
- if (matrix[row].Length.Equals(matrix[row + 1].Length))
- {
- double[] temp = matrix[row].Select(x => x *= 2).ToArray();
- matrix[row] = temp;
- temp = matrix[row + 1].Select(x => x *= 2).ToArray();
- matrix[row + 1] = temp;
- }
- else
- {
- double[] temp = matrix[row].Select(x => x /= 2).ToArray();
- matrix[row] = temp;
- temp = matrix[row + 1].Select(x => x /= 2).ToArray();
- matrix[row + 1] = temp;
- }
- }
- bool isExitLoop = false;
- while (!isExitLoop)
- {
- string input = Console.ReadLine();
- if (input.ToLower().Equals("end"))
- {
- isExitLoop = true;
- }
- else
- {
- string[] commands = input.Split(' ', StringSplitOptions.RemoveEmptyEntries);
- string command = commands[0];
- int newRow = int.Parse(commands[1]);
- int newCol = int.Parse(commands[2]);
- double newValue = double.Parse(commands[3]);
- bool isValidIndexes = ((newRow >= 0) && (newRow < matrix.Length));
- isValidIndexes = ((isValidIndexes) && (newCol >= 0) && (newCol < matrix[newRow].Length));
- if (isValidIndexes)
- {
- switch (command.ToLower())
- {
- case "add":
- matrix[newRow][newCol] += newValue;
- break;
- case "subtract":
- matrix[newRow][newCol] -= newValue;
- break;
- default:
- break;
- }
- }
- }
- }// while (!isExitLoop)
- StringBuilder sb = new StringBuilder();
- for (int row = 0; row < matrix.Length; row++)
- {
- sb.AppendLine(string.Join(" ", matrix[row]));
- }
- Console.WriteLine(sb.ToString());
- }
- }
- }
Advertisement
RAW Paste Data
Copied
Advertisement