Advertisement
dimipan80

Terrorists Win!

May 10th, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. namespace _09.TerroristsWin
  2. {
  3.     using System;
  4.  
  5.     class TerroristsWin
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string text = Console.ReadLine();
  10.             char[] result = text.ToCharArray();
  11.  
  12.             int bombStart = text.IndexOf('|');
  13.             while (bombStart > -1)
  14.             {
  15.                 int bombEnd = text.IndexOf('|', bombStart + 1);
  16.                 int bombSum = 0;
  17.                 for (int i = bombStart + 1; i < bombEnd; i++)
  18.                 {
  19.                     bombSum += (int)text[i];
  20.                     result[i] = '.';
  21.                 }
  22.  
  23.                 int bombPower = bombSum % 10;
  24.                 ReplaceDestroyedCharacters(result, bombStart, bombEnd, bombPower);
  25.  
  26.                 bombStart = text.IndexOf('|', bombEnd + 1);
  27.             }
  28.  
  29.             Console.WriteLine(string.Join(string.Empty, result));
  30.         }
  31.  
  32.         private static void ReplaceDestroyedCharacters(char[] output, int start, int end, int power)
  33.         {
  34.             for (int i = start; i >= start - power && i >= 0; i--)
  35.             {
  36.                 output[i] = '.';
  37.             }
  38.  
  39.             for (int j = end; j <= end + power && j < output.Length; j++)
  40.             {
  41.                 output[j] = '.';
  42.             }
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement