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 ConsoleApplication4
- {
- class Program
- {
- static void Main(string[] args)
- {
- int size = int.Parse(Console.ReadLine());
- string word = Console.ReadLine();
- char[,] charMatrix = new char[size, size];
- //matrix
- int x = 0;
- int y = 0;
- int currentChar = 0;
- while (size > 0)
- {
- for (int i = y; i <= y + size - 1; i++)
- {
- charMatrix[x, i] = word[currentChar % word.Length];
- currentChar++;
- }
- for (int j = x + 1; j <= x + size - 1; j++)
- {
- charMatrix[j, y + size - 1] = word[currentChar % word.Length];
- currentChar++;
- }
- for (int i = y + size - 2; i >= y; i--)
- {
- charMatrix[x + size - 1, i] = word [currentChar % word.Length];
- currentChar++;
- }
- for (int i = x + size - 2; i >= x + 1; i--)
- {
- charMatrix[i, y] = word [currentChar % word.Length];
- currentChar++;
- }
- x = x + 1;
- y = y + 1;
- size = size - 2;
- }
- for (int i = 0; i < charMatrix.GetLength(0); i++)
- {
- for (int j = 0; j < charMatrix.GetLength(1); j++)
- {
- Console.Write(charMatrix[i,j] + " ");
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment