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 1354. Palindrome. Again Palindrome

TLE on #25(help!!!)
Posted by ~Flying Spirit~ 21 Aug 2008 08:15
#include <iostream>
#include <cstring>
#include <vector>

using namespace std;

int main()
{
    char str[20000],str2[10000],str3[10000];
    unsigned int len;
    unsigned int i,j,k;
    vector<char>check;
    char ch;

    while(gets(str))
    {
        len=strlen(str);

        if(len==1)
            cout<<str[0]<<str[0]<<endl;

        else
        {

            for(i=0;i<len;i++)
                str2[i]=str[len-1-i];

            if(strncmp(str,str2,len)==0)
            {
                for(i=1;i<=len;i++)
                {
                    for(j=i;j<len;j++)
                    {
                        ch=str[j];
                        check.push_back(ch);
                    }

                    for(j=0;j<check.size();j++)
                    {
                        str2[j]=check[j];
                        str3[j]=check[check.size()-1-j];
                    }

                    if(strncmp(str2,str3,check.size())==0)
                    {
                        for(k=0;k<i;k++)
                            str[len+k]=str[i-k-1];

                        for(k=0;k<len+i;k++)
                            cout<<str[k];
                        cout<<endl;

                        check.clear();
                        break;
                    }
                    check.clear();
                }
            }

            else
            {
                for(i=0;i<len;i++)
                {
                    for(j=i;j<len;j++)
                    {
                        ch=str[j];
                        check.push_back(ch);
                    }

                    for(j=0;j<check.size();j++)
                    {
                        str2[j]=check[j];
                        str3[j]=check[check.size()-1-j];
                    }

                    if(strncmp(str2,str3,check.size())==0)
                    {
                        for(k=0;k<i;k++)
                            str[len+k]=str[i-k-1];

                        for(k=0;k<len+i;k++)
                            cout<<str[k];
                        cout<<endl;

                        check.clear();
                    break;
                    }
                    check.clear();
                }
            }
        }

    }

    return 0;
}
Re: TLE on #25(help!!!)
Posted by Meni Packeou 21 Aug 2008 15:56
My freind i not c++ but I do at java and AC 0.265
My main function code that


while(true){
            if(n+1==k-n1)if(ch[n]==ch[k-n1])break;
            if(n==k-n1)break;
            if(ch[n]==ch[k-n1]){
                n++;
                n1++;
            }
            else{
                k1++;
                n=k1;
                n1=1;
            }
        }