daily pastebin goal
41%
SHARE
TWEET

Problem 1. Matrix of Palindromes

fight90 Jan 29th, 2018 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace SoftUniNetCore
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             /*
  12.           Write a program to generate and print the following matrix of palindromes of 3 letters with r rows and c columns like at the examples below.
  13.           •   Rows define the first and the last letter: row 0  ‘a’, row 1  ‘b’, row 2  ‘c’, …
  14.           •   Columns + rows define the middle letter:
  15.           o column 0, row 0  ‘a’, column 1, row 0  ‘b’, column 2, row 0  ‘c’, …
  16.           o column 0, row 1  ‘b’, column 1, row 1  ‘c’, column 2, row 1  ‘d’, …
  17.             */
  18.  
  19.             int[] sizeOfMatrix = Console.ReadLine().Split(", ".ToArray(),StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  20.             int row = sizeOfMatrix[0];
  21.             int col = sizeOfMatrix[1];
  22.             string[,] matrix = new string[row,col];
  23.  
  24.             for (int i = 0; i < row; i++)
  25.             {
  26.                 for (int a = 0; a < col; a++)
  27.                 {
  28.                     StringBuilder str = new StringBuilder();
  29.                     char firstAndThirdChar = (char)(i + 97);
  30.                     char secondChar = (char)(i + a + 97);
  31.                     str.Append(firstAndThirdChar.ToString());
  32.                     str.Append(secondChar.ToString());
  33.                     str.Append(firstAndThirdChar.ToString());
  34.                     matrix[i,a] = str.ToString();
  35.                 }
  36.             }
  37.  
  38.             for (int i = 0; i < matrix.GetLength(0); i++)
  39.             {
  40.                 for (int a = 0; a < matrix.GetLength(1); a++)
  41.                 {
  42.                     Console.Write(matrix[i,a] + " ");
  43.                 }
  44.                 Console.WriteLine();
  45.             }
  46.         }
  47.     }
  48. }
RAW Paste Data
Pastebin PRO WINTER Special!
Get 40% OFF Pastebin PRO accounts!
Top