Advertisement
StoyanGrigorov

Untitled

Oct 18th, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 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. using System.Text.RegularExpressions;
  7. //09. Melrah Shake
  8. namespace MelrahShake
  9. {
  10.     class MelrahShake
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string input = Console.ReadLine().Trim();
  15.             string pattern = Console.ReadLine();
  16.  
  17.             bool canShake = true;
  18.  
  19.             while (canShake)
  20.             {
  21.                 int matchCount = Regex.Matches(input, pattern).Count;
  22.  
  23.                 if (matchCount >= 2)
  24.                 {
  25.                     int indxFirst = input.IndexOf(pattern);
  26.                     input = input.Remove(indxFirst, pattern.Length);
  27.                     int indxLast = input.LastIndexOf(pattern);
  28.                     input = input.Remove(indxLast, pattern.Length);
  29.                     Console.WriteLine("Shaked it.");
  30.                     if (pattern.Length >= 2)
  31.                     {
  32.                         pattern = pattern.Remove(pattern.Length / 2, 1);
  33.                     }
  34.                     else
  35.                     {
  36.                         Console.WriteLine("No shake.");
  37.                         break;
  38.                     }
  39.  
  40.                 }
  41.                 else
  42.                 {
  43.                     Console.WriteLine("No shake.");
  44.                     canShake = false;
  45.                     break;
  46.                 }
  47.             }
  48.             Console.WriteLine(input);
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement