Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Numerics;
- using System.Runtime.CompilerServices;
- namespace ConsoleApp9
- {
- class Program
- {
- static void Main(string[] args)
- {
- var size = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- var matrix = new string[size[0], size[1]];
- var queue = new Queue<char>();
- var wordToRemoveWhiteSpace = Console.ReadLine();
- var word = RemoveWhitespace(wordToRemoveWhiteSpace);
- // if currentRow % 2 == 0 for ++
- // else forr
- int currentRow = 0;
- int currentCol = 0;
- while (currentRow < matrix.GetLength(0))
- {
- currentCol = 0;
- if (currentRow % 2 == 0)
- {
- for (int i = 0; i < word.Length; i++)
- {
- queue.Enqueue(word[i]);
- }
- while (currentCol < matrix.GetLength(1))
- {
- if (queue.Any())
- {
- matrix[currentRow, currentCol] = queue.Dequeue().ToString();
- currentCol++;
- }
- else
- {
- for (int i = 0; i < word.Length; i++)
- {
- queue.Enqueue(word[i]);
- }
- }
- }
- }
- else
- {
- for (int j = 0; j < word.Length; j++)
- {
- queue.Enqueue(word[j]);
- }
- if (queue.Any())
- {
- for (int i = matrix.GetLength(1) - 1; i >= 0; i--)
- {
- matrix[currentRow, i] = queue.Dequeue().ToString();
- }
- }
- else
- {
- for (int j = 0; j < word.Length; j++)
- {
- queue.Enqueue(word[j]);
- }
- }
- }
- currentRow++;
- }
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- Console.Write(matrix[row, col]);
- }
- Console.WriteLine();
- }
- }
- public static string RemoveWhitespace(string input)
- {
- return new string(input.ToCharArray()
- .Where(c => !Char.IsWhiteSpace(c))
- .ToArray());
- }
- }
- }
Add Comment
Please, Sign In to add comment