Advertisement
Guest User

Melrah Shake

a guest
Nov 12th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 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 _09.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.                 if (pattern.Length == 0)
  19.                 {
  20.                     Console.WriteLine("No shake.");
  21.                     Console.WriteLine(text);
  22.                     break;
  23.                 }
  24.                 int firstIndex = text.IndexOf(pattern);
  25.                 int lastIndex = text.LastIndexOf(pattern);
  26.  
  27.                 if (firstIndex >= 0 && lastIndex >= 0 && firstIndex != lastIndex)
  28.                 {
  29.                     text = text.Remove(lastIndex, pattern.Length);
  30.                     text = text.Remove(firstIndex, pattern.Length);
  31.                     Console.WriteLine("Shaked it.");
  32.                 }
  33.                 else
  34.                 {
  35.                     Console.WriteLine("No shake.");
  36.                     Console.WriteLine(text);
  37.                     break;
  38.                 }
  39.                 pattern = pattern.Remove(pattern.Length / 2, 1);
  40.             }
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement