Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace TextBombardment
- {
- using System;
- using System.Linq;
- using System.Text;
- public class TextBombardment
- {
- public static char[,] matrix;
- public static void Main()
- {
- string text = Console.ReadLine();
- double cols = double.Parse(Console.ReadLine());
- int rows = (int)Math.Ceiling(text.Length / cols);
- matrix = new char[rows, (int)cols];
- FillTheMatrix(text);
- int[] colsToBomb = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- foreach (int col in colsToBomb)
- {
- BombTheCol(col);
- }
- PrintTheResult(text);
- }
- private static void BombTheCol(int col)
- {
- int row = GetTheStartRow(col);
- while (row != matrix.GetLength(0) && matrix[row, col] != ' ')
- {
- matrix[row, col] = ' ';
- row++;
- }
- }
- private static int GetTheStartRow(int col)
- {
- int rowToReturn = 0;
- while (rowToReturn != matrix.GetLength(0) && matrix[rowToReturn, col] == ' ')
- {
- rowToReturn++;
- }
- return rowToReturn;
- }
- private static void PrintTheResult(string text)
- {
- StringBuilder result = new StringBuilder();
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- result.Append(matrix[row, col]);
- if (result.Length == text.Length)
- {
- goto PrintResult;
- }
- }
- }
- PrintResult:
- Console.WriteLine(result.ToString());
- }
- private static void FillTheMatrix(string text)
- {
- int indexOfText = -1;
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- char toFill = ++indexOfText < text.Length ? text[indexOfText] : ' ';
- matrix[row, col] = toFill;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement