Filkolev

Terrorists Win

May 27th, 2015
49
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2.  
  3. public class TerroristsWin
  4. {
  5.     public static void Main()
  6.     {
  7.         char[] field = Console.ReadLine().ToCharArray();
  8.  
  9.         int startIndex = Array.IndexOf(field, '|');
  10.  
  11.         while (startIndex != -1)
  12.         {
  13.             int endIndex = Array.IndexOf(field, '|', startIndex + 1);
  14.             int power = GetAsciiSum(startIndex, endIndex, field) % 10;
  15.  
  16.             int startIndexToExplode = Math.Max(0, startIndex - power);
  17.             int endIndexToExplode = Math.Min(endIndex + power, field.Length - 1);
  18.  
  19.             ExplodeBomb(startIndexToExplode, endIndexToExplode, field);
  20.  
  21.             startIndex = Array.IndexOf(field, '|', endIndex + 1);
  22.         }
  23.  
  24.         Console.WriteLine(new string(field));
  25.     }
  26.  
  27.     private static void ExplodeBomb(int startIndex, int endIndex, char[] field)
  28.     {
  29.         for (int i = startIndex; i <= endIndex; i++)
  30.         {
  31.             field[i] = '.';
  32.         }
  33.     }
  34.  
  35.     private static int GetAsciiSum(int startIndex, int endIndex, char[] field)
  36.     {
  37.         int sum = 0;
  38.  
  39.         for (int i = startIndex + 1; i < endIndex; i++)
  40.         {
  41.             sum += field[i];
  42.         }
  43.  
  44.         return sum;
  45.     }
  46. }
RAW Paste Data