Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace LegoBlocks
- {
- class Program
- {
- static void Main(string[] args)
- {
- int rows = int.Parse(Console.ReadLine());
- int[][] jaggedArray1 = new int[rows][];
- int[][] jaggedArray2 = new int[rows][];
- jaggedArray1 = ReadNumbers(rows, jaggedArray1);
- jaggedArray2 = ReadNumbers(rows, jaggedArray2);
- bool isLego = true;
- for (int row = 0; row < rows - 1; row++)
- {
- if (jaggedArray1[row].Length + jaggedArray2[row].Length != jaggedArray1[row + 1].Length + jaggedArray2[row + 1].Length)
- {
- isLego = false;
- }
- }
- if (isLego)
- {
- int columns = 0;
- for (int row = 0; row < rows; row++)
- {
- int[] originalArray = jaggedArray2[row];
- jaggedArray2[row] = originalArray.Reverse().ToArray();
- columns = jaggedArray1[row].Length + jaggedArray2[row].Length;
- }
- int[,] resultMatrix = new int[rows,columns];
- for (int row = 0; row < rows; row++)
- {
- int colIndex = 0;
- for (int col = 0; col < columns; col++)
- {
- if (col < jaggedArray1[row].Length)
- {
- resultMatrix[row, col] = jaggedArray1[row][col];
- }
- else
- {
- resultMatrix[row, col] = jaggedArray2[row][colIndex];
- colIndex++;
- }
- }
- }
- for (int row = 0; row < resultMatrix.GetLength(0); row++)
- {
- Console.Write("[");
- for (int col = 0; col < resultMatrix.GetLength(1); col++)
- {
- if (col != resultMatrix.GetLength(1) - 1)
- {
- Console.Write($"{resultMatrix[row, col]}, ");
- }
- else
- {
- Console.Write($"{resultMatrix[row, col]}");
- }
- }
- Console.Write("]");
- Console.WriteLine();
- }
- }
- else
- {
- int sum = SumNumbers(rows, jaggedArray1) + SumNumbers(rows, jaggedArray2);
- Console.WriteLine($"The total number of cells is: {sum}");
- }
- }
- private static int SumNumbers(int rows, int[][] jaggedArray)
- {
- int sum = 0;
- for (int row = 0; row < rows; row++)
- {
- for (int index = 0; index < jaggedArray[row].Length; index++)
- {
- sum += jaggedArray[row][index];
- }
- }
- return sum;
- }
- private static int[][] ReadNumbers(int rows, int[][] jaggedArray)
- {
- for (int row = 0; row < rows; row++)
- {
- int[] inputArray = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- int length = inputArray.Length;
- jaggedArray[row] = new int[length];
- for (int counter = 0; counter < length; counter++)
- {
- jaggedArray[row][counter] = inputArray[counter];
- }
- }
- return jaggedArray;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement