Advertisement
alidzhikov

LegoBlocks

May 7th, 2015
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class LegoBlocks
  5. {
  6.     static void Main()
  7.     {
  8.         int n = int.Parse(Console.ReadLine());
  9.         List<List<string>> firstJaggedArray = ReadJaggedArray(n);
  10.         List<List<string>> secondJaggedArray = ReadJaggedArray(n);
  11.  
  12.         bool canFit = true;
  13.         int rowColSum = firstJaggedArray[0].Count + secondJaggedArray[0].Count;
  14.         for (int i = 1; i < n; i++)
  15.         {
  16.             if (firstJaggedArray[i].Count + secondJaggedArray[i].Count != rowColSum)
  17.             {
  18.                 canFit = false;
  19.                 break;
  20.             }
  21.         }
  22.  
  23.         if (canFit)
  24.         {
  25.             for (int i = 0; i < n; i++)
  26.             {
  27.                 secondJaggedArray[i].Reverse();
  28.                 firstJaggedArray[i].AddRange(secondJaggedArray[i]);
  29.                 Console.WriteLine("[{0}]", String.Join(", ", firstJaggedArray[i]));
  30.             }
  31.         }
  32.         else
  33.         {
  34.             int totalNumberOfCells = 0;
  35.             for (int i = 0; i < n; i++)
  36.             {
  37.                 totalNumberOfCells += firstJaggedArray[i].Count;
  38.                 totalNumberOfCells += secondJaggedArray[i].Count;
  39.             }
  40.             Console.WriteLine("The total number of cells is: {0}", totalNumberOfCells);
  41.         }
  42.     }
  43.  
  44.     private static List<List<string>> ReadJaggedArray(int n)
  45.     {
  46.         List<List<string>> jaggedArray = new List<List<string>>();
  47.  
  48.         string inputLine = String.Empty;
  49.         string[] tokens;
  50.         for (int row = 0; row < n; row++)
  51.         {
  52.             jaggedArray.Add(new List<string>());
  53.             inputLine = Console.ReadLine();
  54.             tokens = inputLine.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
  55.             for (int col = 0; col < tokens.Length; col++)
  56.             {
  57.                 jaggedArray[row].Add(tokens[col]);
  58.             }
  59.         }
  60.         return jaggedArray;
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement