Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace P05.SnakeMoves
- {
- class StartUp
- {
- static void Main(string[] args)
- {
- int[] dimensions = Console.ReadLine().Split(" ",StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- int rows = dimensions[0];
- int cols = dimensions[1];
- var matrix = new char[rows, cols];
- string input = Console.ReadLine();
- var snakeQueue = new Queue<char>(input);
- char oddSymbol = ' ';
- char evenSymbol = ' ';
- int counter = 0;
- for (int row = 0; row < rows; row++)
- {
- counter = 0;
- if (row % 2 == 1)
- {
- oddSymbol = ' ';
- if (snakeQueue.Any() && row > 0)
- {
- for (int col = cols - 1; col >= 0; col--)
- {
- oddSymbol = snakeQueue.Dequeue();
- matrix[row, col] = oddSymbol;
- counter++;
- if (!snakeQueue.Any())
- {
- snakeQueue = new Queue<char>(input);
- break;
- }
- }
- }
- for (int col = cols - 1 - counter; col >= 0; col--)
- {
- oddSymbol = snakeQueue.Dequeue();
- matrix[row, col] = oddSymbol;
- }
- }
- else
- {
- evenSymbol = ' ';
- if (snakeQueue.Any() && row > 0)
- {
- for (int col = 0; col < cols; col++)
- {
- evenSymbol = snakeQueue.Dequeue();
- matrix[row, col] = evenSymbol;
- counter++;
- if (!snakeQueue.Any())
- {
- snakeQueue = new Queue<char>(input);
- break;
- }
- }
- }
- for (int col = counter; col < cols; col++)
- {
- evenSymbol = snakeQueue.Dequeue();
- matrix[row, col] = evenSymbol;
- }
- }
- }
- PrintMatrix(rows, cols, matrix);
- }
- private static void PrintMatrix(int rows, int cols, char[,] matrix)
- {
- for (int row = 0; row < rows; row++)
- {
- for (int col = 0; col < cols; col++)
- {
- Console.Write(matrix[row, col]);
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement