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 SpiralMatrix
- {
- class SpiralMatrix
- {
- static void Main(string[] args)
- {
- int sizeOfMatrix = int.Parse(Console.ReadLine());
- string keyword = Console.ReadLine();
- char[,] matrix = new char[sizeOfMatrix, sizeOfMatrix];
- int counter = 0;
- int lastCol = sizeOfMatrix;
- int startPosition1 = 1;
- int lastRow = sizeOfMatrix;
- int startPosition2 = sizeOfMatrix - 2;
- int firstCol = 1;
- int startPosition3 = sizeOfMatrix - 2;
- for (int row = 0; row < sizeOfMatrix; row++)
- {
- for (int col = 0; col < sizeOfMatrix; col++)
- {
- if (counter == keyword.Length)
- {
- counter = 0;
- }
- matrix[row, col] = keyword[counter];
- counter++;
- if (col == lastCol - 1)
- {
- for (int i = startPosition1; i < lastCol; i++)
- {
- if (counter == keyword.Length)
- {
- counter = 0;
- }
- matrix[i, col] = keyword[counter];
- counter++;
- if (i == lastRow - 1)
- {
- for (int j = startPosition2; j >= 0 ; j--)
- {
- if (counter == keyword.Length)
- {
- counter = 0;
- }
- matrix[i, j] = keyword[counter];
- counter++;
- if (j == 0)
- {
- for (int k = startPosition3; k >= firstCol; k--)
- {
- if (counter == keyword.Length)
- {
- counter = 0;
- }
- matrix[k, j] = keyword[counter];
- counter++;
- }
- }
- }
- }
- }
- lastCol--;
- startPosition1++;
- lastRow--;
- startPosition2++;
- firstCol--;
- startPosition3++;
- }
- }
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement