WA on Kickstart Round G — Question A Kick_start

Правка en2, от pzwnt, 2020-11-11 12:50:33

Hello, I'm looking for an explanation about why my code gives wrong output in the platform. Unfortunately google platform does not provide the input test set, so I'm clueless. I've locally tested it with random input and they all seem right to me; I'd appreciate anyone explaining or providing an input that breaks my impl. and outputs wrong answer. Thanks advance!

This is C# imple.; basically in first iteration I keep the indexes of 'START' substrings and then counting the pairs on the second loop.

private static int solve(string text)
    {
        if (text == string.Empty)
            return 0;

        string s1 = "KICK";
        string s2 = "START";
        List<int> indexes = new List<int>();
        int cnt = 0;
        int start_s1 = 0;
        for (int i = 0; i < text.Length; i++)
        {
            if((i + s1.Length) > text.Length)
            {
                break;
            }

            if (text.Substring(i, 4).Equals(s1))
            {
                start_s1 = i;
                for (int j = i + 4; j < text.Length; j++)
                {
                    if((j + s2.Length) > text.Length)
                    {
                        break;
                    }
                    if (text.Substring(j, 5).Equals(s2))
                    {
                        indexes.Add(j);
                        cnt++;
                    }                        
                }
                break;
            }              
        }

        for (int i = start_s1 + 4;  i < text.Length; i++)
        {
            if (i + s1.Length > text.Length)
                break;

            if (text.Substring(i, 4).Equals(s1))
            {
                for (int j = 0; j < indexes.Count; j++)
                {
                    if (i > indexes[j])
                    { continue; }
                    else 
                    { cnt += indexes.Count - j; }
                    break;                        
                }
            }
        }
        return cnt;
    }
Теги #googlekickstart, c#, #wronganswer

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский pzwnt 2020-11-11 12:50:33 11 Tiny change: 'oop.\n\n\nprivate st' -> 'oop.\n\n\n private st'
en1 Английский pzwnt 2020-11-11 12:49:37 2371 Initial revision (published)