Advertisement
Guest User

Untitled

a guest
May 13th, 2017
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace _01.Melrah_Shake
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             var text = Console.ReadLine();
  15.             var pattern = new Regex(Console.ReadLine());
  16.  
  17.             while (true)
  18.             {
  19.                 var patternSTR = pattern.ToString();
  20.                 var matches = pattern.Matches(text);
  21.  
  22.                 if (matches.Count < 2 || patternSTR.Length==0)
  23.                 {
  24.                     break;
  25.                 }
  26.  
  27.                 var firstIndex = text.IndexOf(patternSTR);
  28.                 text = text.Remove(firstIndex, patternSTR.Length);
  29.                 var lastIndex = text.LastIndexOf(patternSTR);
  30.                 text = text.Remove(lastIndex, patternSTR.Length);
  31.                
  32.                     patternSTR = patternSTR.Remove(patternSTR.Length / 2, 1);                
  33.  
  34.                 pattern = new Regex(patternSTR);
  35.  
  36.                 Console.WriteLine("Shaked it.");
  37.             }
  38.             Console.WriteLine("No shake.");
  39.             Console.WriteLine(text);
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement