View difference between Paste ID: gNcuPQe9 and DTR0hxxA
SHOW: | | - or go back to the newest paste.
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6
7
namespace MatrixShuffle
8
{
9
    class Program
10
    {
11
        static void Main(string[] args)
12
        {
13
            int matrixSize = int.Parse(Console.ReadLine());
14
            string input = Console.ReadLine();
15
            char[,] matrix = new char[matrixSize, matrixSize];
16
            int row = 0;
17
            int col = 0;
18
            string direction = "right";
19
            int matrixLength = matrixSize * matrixSize;
20
21
22
                for (int i = 0; i < matrixLength; i++)
23
                {
24
                    if (direction == "right" && (col > matrixSize - 1 || matrix[row, col] != default(char)))
25
                    {
26
                        direction = "down";
27
                        col--;
28
                        row++;
29
                    }
30
                    if (direction == "down" && (row > matrixSize - 1 || matrix[row, col] != default(char)))
31
                    {
32
                        direction = "left";
33
                        row--;
34
                        col--;
35
                    }
36
                    if (direction == "left" && (col < 0 || matrix[row, col] != default(char)))
37
                    {
38
                        direction = "up";
39
                        col++;
40
                        row--;
41
                    }
42
43
                    if (direction == "up" && (row < 0 || matrix[row, col] != default(char)))
44
                    {
45
                        direction = "right";
46
                        row++;
47
                        col++;
48
                    }
49
                    if (i > input.Length - 1)
50
                    {
51
                        matrix[row, col] = ' ';
52
                    }
53
                    else
54
                    {
55
                        matrix[row, col] = input[i];
56
                    }
57
58
                    if (direction == "right")
59
                    {
60
                        col++;
61
                    }
62
                    if (direction == "down")
63
                    {
64
                        row++;
65
                    }
66
                    if (direction == "left")
67
                    {
68
                        col--;
69
                    }
70
                    if (direction == "up")
71
                    {
72
                        row--;
73
                    }
74
                }
75
76
                List<char> firstString = new List<char>();
77
                List<char> secondString = new List<char>();
78
79
                for (int rr = 0; rr < matrix.GetLength(0); rr++)
80
                {
81
                    if (rr % 2 == 0)
82
                    {
83
                        for (int cc = 0; cc < matrix.GetLength(1); cc = cc + 2)
84
                        {
85
                            firstString.Add(matrix[rr, cc]);
86
                        }
87
                        for (int cc = 1; cc < matrix.GetLength(1); cc = cc + 2)
88
                        {
89
                            secondString.Add(matrix[rr, cc]);
90
                        }
91
                    }
92
                    else
93
                    {
94
                        for (int cc = 0; cc < matrix.GetLength(1); cc = cc + 2)
95
                        {
96
                            secondString.Add(matrix[rr, cc]);
97
                        }
98
                        for (int cc = 1; cc < matrix.GetLength(1); cc = cc + 2)
99
                        {
100
                            firstString.Add(matrix[rr, cc]);
101
                        }
102
                    }
103
                }
104
105
                bool isPalindrome = false;
106
                
107
                string convertFirstString = new string(firstString.ToArray());
108
                string convertSecondString = new string(secondString.ToArray());
109
110
                string straightInput = convertFirstString + convertSecondString;
111
                string straightInputToLower = straightInput.ToLower();
112
                //var a = straightInputToLower.ToCharArray();
113
                //Array.Reverse(a);
114
115
                var original = straightInputToLower;
116
                var reversed = new string(original.ToCharArray().Reverse().ToArray());
117
118
                if (original == reversed)
119
                {
120
                    isPalindrome = true;
121
                }
122
123
                if (isPalindrome)
124
                {
125
                    Console.WriteLine("<div style='background-color:#4FE000'>" + straightInput + "</div>");
126
                }
127
                else
128
                {
129
                    Console.WriteLine("<div style='background-color:#E0000F'>" + straightInput + "</div>");
130
                }
131
        }
132
    }
133
}