Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace SnakeMove
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] dimensions = Console.ReadLine()
- .Split(" ", StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- int rows = dimensions[0];
- int cols = dimensions[1];
- char[,] matrixFromString = new char[rows, cols];
- string text = Console.ReadLine();
- Queue<char> inputChars = new Queue<char>(text);
- for (int rowIndex = 0; rowIndex < rows; rowIndex++)
- {
- for (int colIndex = 0; colIndex < cols; colIndex++)
- {
- if (rowIndex % 2 != 0)
- {
- char currentSymbol = inputChars.Dequeue();
- matrixFromString[rowIndex, cols - colIndex - 1] = currentSymbol;
- inputChars.Enqueue(currentSymbol);
- }
- else
- {
- char currentSymbol = inputChars.Dequeue();
- matrixFromString[rowIndex, colIndex] = currentSymbol;
- inputChars.Enqueue(currentSymbol);
- }
- }
- }
- PrintSnake(matrixFromString);
- }
- private static void PrintSnake(char[,] matrixFromString)
- {
- for (int row = 0; row < matrixFromString.GetLength(0); row++)
- {
- for (int col = 0; col < matrixFromString.GetLength(1); col++)
- {
- Console.Write(matrixFromString[row, col] + "");
- }
- Console.WriteLine();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment