Advertisement
Prohause

Remove sequence

Oct 9th, 2018
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. using System;
  2.  
  3. namespace test
  4. {
  5. internal class Program
  6. {
  7. private static void Main(string[] args)
  8. {
  9. Console.WriteLine("Enter the length of the marble sequence");
  10. int length = int.Parse(Console.ReadLine());
  11.  
  12. string[] marbles = new string[length];
  13. for (int i = 0; i < length; i++)
  14. {
  15. marbles[i] = Console.ReadLine();
  16. }
  17.  
  18. bool sequence = true;
  19. while (sequence)
  20. {
  21. sequence = false;
  22. for (int i = 0; i < marbles.Length; i++)
  23. {
  24. for (int j = 0; j < marbles[i].Length - 2; j++)
  25. {
  26. if (marbles[i][j] != marbles[i][j + 1] || marbles[i][j] != marbles[i][j + 2])
  27. {
  28. continue;
  29. }
  30.  
  31. marbles[i] = marbles[i].Substring(0, j) + marbles[i].Substring(j + 3, marbles[i].Length - j - 3);
  32. sequence = true;
  33. break;
  34. }
  35. }
  36. }
  37.  
  38. for (int i = 0; i < marbles.Length; i++)
  39. {
  40. Console.WriteLine(marbles[i]);
  41. }
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement