Separate the Numbers

  • + 0 comments

    C#

    public static void separateNumbers(string s)
    {
        var print = "NO";
    
        if (s.Length > 1)
        {
            var sequenceStart = string.Empty;
    
            for (int i = 0; i < s.Length / 2; i++)
            {
                sequenceStart += s[i];
                var num = long.Parse(sequenceStart);
                var sequence = string.Empty;
    
                while (s.Length > sequence.Length)
                {
                    if (!s.StartsWith(sequence)) break;
    
                    sequence += num;
                    ++num;
                }
    
                if (s.StartsWith(sequence))
                {
                    print = $"YES {sequenceStart}";
                }
    
                if (s.Length == sequence.Length) break;
            }
        }
    
        Console.WriteLine(print);
    }