Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace SoftUniNetCore
- {
- class Program
- {
- static void Main(string[] args)
- {
- /*
- 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.
- • Rows define the first and the last letter: row 0 ‘a’, row 1 ‘b’, row 2 ‘c’, …
- • Columns + rows define the middle letter:
- o column 0, row 0 ‘a’, column 1, row 0 ‘b’, column 2, row 0 ‘c’, …
- o column 0, row 1 ‘b’, column 1, row 1 ‘c’, column 2, row 1 ‘d’, …
- */
- int[] sizeOfMatrix = Console.ReadLine().Split(", ".ToArray(),StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- int row = sizeOfMatrix[0];
- int col = sizeOfMatrix[1];
- string[,] matrix = new string[row,col];
- for (int i = 0; i < row; i++)
- {
- for (int a = 0; a < col; a++)
- {
- StringBuilder str = new StringBuilder();
- char firstAndThirdChar = (char)(i + 97);
- char secondChar = (char)(i + a + 97);
- str.Append(firstAndThirdChar.ToString());
- str.Append(secondChar.ToString());
- str.Append(firstAndThirdChar.ToString());
- matrix[i,a] = str.ToString();
- }
- }
- for (int i = 0; i < matrix.GetLength(0); i++)
- {
- for (int a = 0; a < matrix.GetLength(1); a++)
- {
- Console.Write(matrix[i,a] + " ");
- }
- Console.WriteLine();
- }
- }
- }
- }
RAW Paste Data



