Advertisement
iliqnvidenov

Untitled

Jan 28th, 2015
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Bombardent
  6. {
  7.     static void Main()
  8.     {
  9.         string inputText = Console.ReadLine();
  10.         int width = int.Parse(Console.ReadLine());
  11.         string strBombs = Console.ReadLine();
  12.         double rows = Math.Ceiling((double)inputText.Length / width);
  13.         int rowsCount = (int)rows;
  14.         int[] bombs = strBombs.Split(' ').Select(n => Convert.ToInt32(n)).ToArray();
  15.         char[] text = inputText.ToCharArray();
  16.         char[,] matrix = new char[rowsCount, width];
  17.         int mark = 0;
  18.         for (int i = 0; i < rowsCount; i++)
  19.         {
  20.             for (int j = 0; j < width; j++, mark++)
  21.             {
  22.                 if (text.Length > mark)
  23.                 {
  24.                     matrix[i, j] = text[mark];
  25.                 }
  26.                 else
  27.                 {
  28.                     matrix[i, j] = ' ';
  29.                 }
  30.             }
  31.         }
  32.         bombing(matrix, bombs);
  33.     }
  34.     static void bombing(char[,] matrix, int[] bombs)
  35.     {
  36.         List<char> output = new List<char>();
  37.         for (int i = 0; i < bombs.Length; i++)
  38.         {
  39.             bool bombarded = false;
  40.             int bomb = bombs[i];
  41.             for (int j = 0; j < matrix.GetLongLength(0); j++)
  42.             {
  43.                 if (matrix[j, bomb] != ' ')
  44.                 {
  45.                     bombarded = true;
  46.                     matrix[j, bomb] = ' ';
  47.                 }
  48.                 else if (bombarded)
  49.                 {
  50.                     break;
  51.                 }
  52.             }
  53.         }
  54.         for (int i = 0; i < matrix.GetLongLength(0); i++)
  55.         {
  56.             for (int j = 0; j < matrix.GetLongLength(1); j++)
  57.             {
  58.                 output.Add(matrix[i, j]);
  59.             }
  60.         }
  61.         foreach (var chars in output)
  62.         {
  63.             Console.Write(chars);
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement