ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1423. String Tale

What's wrong with my C# code? It is giving wrong answer in case # 2...
Posted by Alaska . PK 26 Feb 2011 00:03


            long stringLength = Convert.ToInt32(Console.ReadLine());
            string S = Console.ReadLine();
            string T = Console.ReadLine();
            long temp = 0;
            bool check = false;
            for (long i = 0; i < stringLength; i++)
            {
                S = S[Convert.ToInt32(stringLength) - 1] +
                                     S.Substring(0,  Convert.ToInt32(stringLength) - 1);
                if (S == T)
                {
                    temp = i + 1;
                    check = true;
                    break;
                }
            }
            if (check && temp < stringLength)
                Console.WriteLine(temp);
            else
                Console.WriteLine(-1);