Simeon1995

Untitled

Oct 28th, 2017
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 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 textCopy = string.Empty;
  15. string pattern = Console.ReadLine();
  16. while (true)
  17. {
  18. if (text.Contains(pattern))
  19. {
  20. int firstIndex = text.IndexOf(pattern);
  21. textCopy = text.Remove(firstIndex, pattern.Length);
  22. if (textCopy.Contains(pattern))
  23. {
  24. int lastIndex = textCopy.LastIndexOf(pattern);
  25. text = textCopy.Remove(lastIndex, pattern.Length);
  26. Console.WriteLine("Shaked it.");
  27. }
  28. else
  29. {
  30. Console.WriteLine("No shake.");
  31. Console.WriteLine(text);
  32. break;
  33. }
  34. }
  35. else
  36. {
  37. Console.WriteLine("No shake.");
  38. Console.WriteLine(text);
  39. break;
  40. }
  41. if (pattern.Length<=1)
  42. {
  43. Console.WriteLine("No shake.");
  44. Console.WriteLine(text);
  45. break;
  46. }
  47. int patternIndexToRemove = pattern.Length / 2;
  48. pattern = pattern.Remove(patternIndexToRemove, 1);
  49. }
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment