Advertisement
enevlogiev

TxtBombardment

Dec 22nd, 2014
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.85 KB | None | 0 0
  1. using System;
  2.  
  3. class TxtBomb
  4. {
  5.     static void Main()
  6.     {
  7.         string text = Console.ReadLine();
  8.         int lineWidth = int.Parse(Console.ReadLine());
  9.         string[] bombsInput = Console.ReadLine().Split();
  10.  
  11.         double rows = text.Length / (double)lineWidth;
  12.         rows = Math.Ceiling(rows);
  13.         char[,] matrix = new char[(int)rows, lineWidth];
  14.        
  15.         //fill the matrix
  16.         int counter = 0;
  17.         for (int row = 0; row < (int)rows; row++)
  18.         {
  19.             for (int col = 0; col < lineWidth; col++)
  20.             {
  21.                 matrix[row, col] = text[counter];
  22.                 counter++;
  23.                 if (counter == text.Length)
  24.                 {
  25.                     break;
  26.                 }
  27.             }
  28.         }
  29.  
  30.         int[] bombs = new int[bombsInput.Length];
  31.         for (int i = 0; i < bombsInput.Length; i++)
  32.         {
  33.             bombs[i] = int.Parse(bombsInput[i]);
  34.         }
  35.  
  36.         //bombard
  37.         for (int i = 0; i < bombs.Length; i++)
  38.         {
  39.             int bomb = bombs[i];
  40.             bool damageDone = false; //if the first row is empty, the bomb should continue
  41.             for (int j = 0; j < (int)rows; j++)
  42.             {
  43.                 if (matrix[j, bomb] == ' ' && damageDone)
  44.                 {
  45.                     break;
  46.                 }
  47.                 else if (matrix[j, bomb] != ' ')
  48.                 {
  49.                     matrix[j, bomb] = ' ';
  50.                     damageDone = true;
  51.                 }
  52.             }
  53.         }
  54.         // print
  55.         for (int i = 0; i < (int)rows; i++)
  56.         {
  57.             for (int j = 0; j < lineWidth; j++)
  58.             {
  59.                 if (matrix[i, j] == '\0' )
  60.                 {
  61.                     continue;
  62.                 }
  63.                 Console.Write(matrix[i, j]);
  64.             }
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement