veno0o

Untitled

May 6th, 2020
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Numerics;
  5. using System.Runtime.CompilerServices;
  6.  
  7.  
  8. namespace ConsoleApp9
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             var size = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  15.  
  16.             var matrix = new string[size[0], size[1]];
  17.             var queue = new Queue<char>();
  18.             var wordToRemoveWhiteSpace = Console.ReadLine();
  19.             var word = RemoveWhitespace(wordToRemoveWhiteSpace);
  20.  
  21.             // if currentRow % 2 == 0 for ++
  22.             // else forr
  23.            
  24.             int currentRow = 0;
  25.             int currentCol = 0;
  26.             while (currentRow < matrix.GetLength(0))
  27.             {
  28.                 currentCol = 0;
  29.  
  30.                 if (currentRow % 2 == 0)
  31.                 {
  32.                     for (int i = 0; i < word.Length; i++)
  33.                     {
  34.                         queue.Enqueue(word[i]);
  35.                     }
  36.  
  37.  
  38.                     while (currentCol < matrix.GetLength(1))
  39.                     {
  40.                         if (queue.Any())
  41.                         {
  42.                             matrix[currentRow, currentCol] = queue.Dequeue().ToString();
  43.                             currentCol++;
  44.                         }
  45.                         else
  46.                         {
  47.                             for (int i = 0; i < word.Length; i++)
  48.                             {
  49.                                 queue.Enqueue(word[i]);
  50.                             }
  51.                         }
  52.  
  53.                     }
  54.                 }
  55.                 else
  56.                 {
  57.  
  58.                     for (int j = 0; j < word.Length; j++)
  59.                     {
  60.                         queue.Enqueue(word[j]);
  61.                     }
  62.  
  63.                     if (queue.Any())
  64.                     {
  65.                         for (int i = matrix.GetLength(1) - 1; i >= 0; i--)
  66.                         {
  67.  
  68.                             matrix[currentRow, i] = queue.Dequeue().ToString();
  69.  
  70.                         }
  71.                     }
  72.                     else
  73.                     {
  74.                         for (int j = 0; j < word.Length; j++)
  75.                         {
  76.                             queue.Enqueue(word[j]);
  77.                         }
  78.                     }
  79.  
  80.  
  81.                 }
  82.  
  83.                 currentRow++;
  84.             }
  85.  
  86.  
  87.             for (int row = 0; row < matrix.GetLength(0); row++)
  88.             {
  89.                 for (int col = 0; col < matrix.GetLength(1); col++)
  90.                 {
  91.                     Console.Write(matrix[row, col]);
  92.                 }
  93.  
  94.                 Console.WriteLine();
  95.             }
  96.  
  97.         }
  98.  
  99.         public static string RemoveWhitespace(string input)
  100.         {
  101.             return new string(input.ToCharArray()
  102.                 .Where(c => !Char.IsWhiteSpace(c))
  103.                 .ToArray());
  104.  
  105.         }
  106.     }
  107. }
Add Comment
Please, Sign In to add comment