Advertisement
martinvalchev

Melrah_Shake

Feb 21st, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 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 Melrah_Shake
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string text = Console.ReadLine();
  14.             string pattern = Console.ReadLine();
  15.  
  16.             while (true)
  17.             {
  18.  
  19.                 int firstIndex = text.IndexOf(pattern);
  20.                 int lastIndex = text.LastIndexOf(pattern);
  21.  
  22.                 if (firstIndex > -1 && lastIndex > -1 && pattern.Length > 0)
  23.                 {
  24.                     firstIndex = text.IndexOf(pattern);
  25.                     text = text.Remove(firstIndex, pattern.Length);
  26.  
  27.                     lastIndex = text.LastIndexOf(pattern);
  28.                     text = text.Remove(lastIndex, pattern.Length);
  29.  
  30.                     pattern = pattern.Remove(pattern.Length / 2, 1);
  31.  
  32.                     Console.WriteLine("Shaked it.");
  33.                 }
  34.                 else
  35.                 {
  36.                     Console.WriteLine("No shake.");
  37.                     Console.WriteLine(text);
  38.                     break;
  39.                 }
  40.  
  41.             }
  42.  
  43.  
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement