Advertisement
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;
- using System.Threading.Tasks;
- namespace MatrixShuffle
- {
- class Program
- {
- static void Main(string[] args)
- {
- int matrixSize = int.Parse(Console.ReadLine());
- string input = Console.ReadLine();
- char[,] matrix = new char[matrixSize, matrixSize];
- int row = 0;
- int col = 0;
- string direction = "right";
- int matrixLength = matrixSize * matrixSize;
- for (int i = 0; i < matrixLength; i++)
- {
- if (direction == "right" && (col > matrixSize - 1 || matrix[row, col] != default(char)))
- {
- direction = "down";
- col--;
- row++;
- }
- if (direction == "down" && (row > matrixSize - 1 || matrix[row, col] != default(char)))
- {
- direction = "left";
- row--;
- col--;
- }
- if (direction == "left" && (col < 0 || matrix[row, col] != default(char)))
- {
- direction = "up";
- col++;
- row--;
- }
- if (direction == "up" && (row < 0 || matrix[row, col] != default(char)))
- {
- direction = "right";
- row++;
- col++;
- }
- if (i > input.Length - 1)
- {
- matrix[row, col] = ' ';
- }
- else
- {
- matrix[row, col] = input[i];
- }
- if (direction == "right")
- {
- col++;
- }
- if (direction == "down")
- {
- row++;
- }
- if (direction == "left")
- {
- col--;
- }
- if (direction == "up")
- {
- row--;
- }
- }
- List<char> firstString = new List<char>();
- List<char> secondString = new List<char>();
- for (int rr = 0; rr < matrix.GetLength(0); rr++)
- {
- if (rr % 2 == 0)
- {
- for (int cc = 0; cc < matrix.GetLength(1); cc = cc + 2)
- {
- firstString.Add(matrix[rr, cc]);
- }
- for (int cc = 1; cc < matrix.GetLength(1); cc = cc + 2)
- {
- secondString.Add(matrix[rr, cc]);
- }
- }
- else
- {
- for (int cc = 0; cc < matrix.GetLength(1); cc = cc + 2)
- {
- secondString.Add(matrix[rr, cc]);
- }
- for (int cc = 1; cc < matrix.GetLength(1); cc = cc + 2)
- {
- firstString.Add(matrix[rr, cc]);
- }
- }
- }
- bool isPalindrome = false;
- string convertFirstString = new string(firstString.ToArray());
- string convertSecondString = new string(secondString.ToArray());
- string straightInput = convertFirstString + convertSecondString;
- string straightInputToLower = straightInput.ToLower();
- //var a = straightInputToLower.ToCharArray();
- //Array.Reverse(a);
- var original = straightInputToLower;
- var reversed = new string(original.ToCharArray().Reverse().ToArray());
- if (original == reversed)
- {
- isPalindrome = true;
- }
- if (isPalindrome)
- {
- Console.WriteLine("<div style='background-color:#4FE000'>" + straightInput + "</div>");
- }
- else
- {
- Console.WriteLine("<div style='background-color:#E0000F'>" + straightInput + "</div>");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement