Advertisement
bullit3189

Melrah Shake - String and Text Archive

Feb 26th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _09MelrahShake
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. string input = Console.ReadLine();
  10. string pattern = Console.ReadLine();
  11.  
  12. while (input.Length>0 && pattern.Length>0)
  13. {
  14. int firstIndex = input.IndexOf(pattern);
  15. int lastIndex = input.LastIndexOf(pattern);
  16.  
  17. if (firstIndex>=0 && lastIndex>=0 && firstIndex!=lastIndex)
  18. {
  19. input = input.Remove(firstIndex, pattern.Length);
  20. lastIndex = input.LastIndexOf(pattern);
  21. input = input.Remove(lastIndex, pattern.Length);
  22.  
  23. pattern = pattern.Remove(pattern.Length / 2, 1);
  24. Console.WriteLine("Shaked it.");
  25. }
  26. else
  27. {
  28. break;
  29. }
  30. }
  31.  
  32. Console.WriteLine("No shake.");
  33. Console.WriteLine(input);
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement