Advertisement
ivanov_ivan

TextBombardment

Nov 26th, 2015
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace TextBombardtment
  8. {
  9.     class TextBombardtment
  10.     {
  11.         static void Main()
  12.         {
  13.             StringBuilder input = new StringBuilder();
  14.             input.Append(Console.ReadLine());
  15.             int lineWidth = int.Parse(Console.ReadLine());
  16.             int[] columnsToDestroy = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  17.  
  18.             for(int i = 0; i < columnsToDestroy.Length; i++)
  19.             {
  20.                 while(columnsToDestroy[i] <= input.Length)
  21.                 {
  22.                     char getCurrentChar = input[columnsToDestroy[i]];
  23.                     char nextChar = ' ';
  24.                     if( columnsToDestroy[i] + lineWidth <= input.Length)
  25.                     {
  26.                         nextChar = ( input[columnsToDestroy[i] + lineWidth] );
  27.                     }
  28.  
  29.                     if(!char.IsWhiteSpace(nextChar))
  30.                     {
  31.                         input.Replace(getCurrentChar , ' ' , columnsToDestroy[i] , 1);
  32.                         columnsToDestroy[i] = columnsToDestroy[i] + lineWidth;
  33.                     }
  34.                     else
  35.                     {
  36.                         input.Replace(getCurrentChar , ' ' , columnsToDestroy[i] , 1);
  37.                         columnsToDestroy[i] = columnsToDestroy[i] + lineWidth;
  38.                         break;
  39.                     }
  40.                    
  41.                 }
  42.             }
  43.  
  44.             Console.WriteLine(input);
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement