Advertisement
simeon3000

LegoBlocks

Jan 31st, 2018
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.82 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace P07.LegoBlocks
  5. {
  6.     class LegoBlocks
  7.     {
  8.         static void Main()
  9.         {
  10.             int rowsNum = int.Parse(Console.ReadLine());
  11.  
  12.             int[][] leftBlock = new int[rowsNum][];
  13.             int[][] rightBlock = new int[rowsNum][];
  14.  
  15.             for (int r = 0; r < rowsNum; r++)
  16.             {
  17.                 leftBlock[r] = Console.ReadLine()
  18.                     .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  19.                     .Select(int.Parse).ToArray();
  20.             }
  21.  
  22.             for (int r = 0; r < rowsNum; r++)
  23.             {
  24.                 rightBlock[r] = Console.ReadLine()
  25.                     .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  26.                     .Select(int.Parse).Reverse().ToArray();
  27.             }
  28.            
  29.             int rowLenght = leftBlock[0].Length + rightBlock[0].Length;
  30.             int allElements = 0;
  31.             bool isMatch = true;
  32.            
  33.             for (int r = 0; r < rowsNum; r++)
  34.             {
  35.                 int currentLenght = leftBlock[r].Length + rightBlock[r].Length;
  36.                 if (currentLenght != rowLenght)
  37.                 {
  38.                     isMatch = false;
  39.                 }
  40.  
  41.                 allElements += currentLenght;
  42.             }
  43.  
  44.             if (isMatch)
  45.             {
  46.                 int[] resultRow = new int[rowLenght];
  47.                 for (int r = 0; r < rowsNum; r++)
  48.                 {
  49.                     resultRow = leftBlock[r].Concat(rightBlock[r]).ToArray();
  50.                     Console.WriteLine($"[{string.Join(", ", resultRow)}]");
  51.                 }
  52.             }
  53.             else
  54.             {
  55.                 Console.WriteLine($"The total number of cells is: {allElements}");
  56.             }
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement