Advertisement
Guest User

03. Lego Blocks

a guest
Oct 2nd, 2015
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _08LegoBlocks
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.  
  15.             // Create the matrix.
  16.             List<List<int>> matrix = new List<List<int>>();
  17.             List<int> row = new List<int>();
  18.  
  19.             for (int j = 1; j <= 2 * n; j++)
  20.             {
  21.                 row = Console.ReadLine().Split(' ').Where(s => !string.IsNullOrWhiteSpace(s)).Select(int.Parse).ToList(); // Each row is a list.
  22.                 matrix.Add(row); // Add each row to a nested list named matrix.
  23.             }
  24.  
  25.             // Check if two blocks fit together.
  26.             bool fit = true;
  27.  
  28.             for (int i = 1; i < n; i++)
  29.             {
  30.                 if (((matrix[i].Count + matrix[i + n].Count)) != (matrix[i - 1].Count + matrix[i - 1 + n].Count))
  31.                 {
  32.                     fit = false;
  33.                     break;
  34.                 }
  35.             }
  36.  
  37.             // Print results.
  38.             if (fit)
  39.             {
  40.                 for (int i = 0; i < n; i++)
  41.                 {
  42.                     matrix[i + n].Reverse();
  43.                     Console.WriteLine("[" + string.Join(", ", matrix[i]) + ", " + string.Join(", ", matrix[i + n].ToList()) + "]");
  44.                 }
  45.             }
  46.             else
  47.             {
  48.                 int sum = 0;
  49.  
  50.                 // Sum of cells calculation.
  51.                 for (int i = 0; i < (2 * n); i++)
  52.                 {
  53.                     sum += matrix[i].Count;
  54.                 }
  55.  
  56.                 Console.WriteLine("The total number of cells is: {0}", sum);
  57.             }
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement