fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. string[] inputs = {
  8. "3123124245252342345423523525235235",
  9. "9090909090909090",
  10. "727519727519727519"
  11. };
  12. foreach(string input in inputs)
  13. Console.WriteLine(string.Format("{0}: pattern {1}", input, Check(input)));
  14. }
  15.  
  16. public static string Check(string s)
  17. {
  18. for(int i = 0; i<=s.Length / 2;i++)
  19. {
  20. string part = s.Substring(0,i+1);
  21. if((s.Length % part.Length) == 0)
  22. {
  23. string attempt = string.Empty;
  24. for(int k = 0; k < (s.Length / part.Length);k++)
  25. attempt += part;
  26. if(attempt == s)
  27. return part;
  28. }
  29. }
  30. return "not found";
  31. }
  32. }
Success #stdin #stdout 0.01s 29664KB
stdin
Standard input is empty
stdout
3123124245252342345423523525235235: pattern not found
9090909090909090: pattern 90
727519727519727519: pattern 727519