1 / 2
May 2018

Yes, my code gives correct output at-
3
929993774
97268982378
972692378
please try to where my code gives wrong answer. I have submitted a shorter version but it still gives wrong answer.By the way thanks for sending the test cases.My1 new code is-
#include
#include<stdio.h>
#include
using namespace std;
char s[1000003];
int main()
{

long long int t,mm;
int flaa=0,prte=0;
scanf("%lld",&t);
for(mm=0;mm<t;mm++)
{
    long long i=0,l,j;
    scanf("%s",s);
    while(s[i]!='\0')
    ++i;
    //cout<<i<<"\n";
    j=i;
    //digits achieved
    while(i)
    {
        if(s[i-1]=='9')
        {s[i-1]='0';}//printf("%c\n",s[i-1]);}
        else
        {++s[i-1];break;}
        --i;
    }
    i=j;
    if(s[0]=='0')
    {
        s[0]='1';
        s[i]='1';
        s[i+1]='\0';
        ++i;++j;
    }
    //cout<<s<<"\n";  
    //increased the digit by one.
    
    //*********************************+++++++*********************************//
    l=i/2-1;
    while(l!=-1)
    {
        //GAME BEGINS FOR ODD NUMBERS.
        if(s[i-l-1]!=s[l]&&flaa==0&&i%2!=0)
        {
            if(s[l]<s[i-1-l]&&s[j/2]!='9')
            {
                ++s[j/2];
                flaa=1;
            }
            //flag on, for odd digits, mid!=9
            else if(s[l]<s[i-1-l]&&s[j/2]=='9')
            {
                flaa=1;
                j=j/2;
                while(j!=l-1)
                {
                    if(s[j]=='9')
                    {
                        s[j]='0';
                        --j;
                    }
                    else
                    {++s[j];   break;}
                }
                j=i;
            }
            //flag on, for odd digits when mid==9 & continue increasing digits on left.
            else if(s[l]>s[i-1-l])
            {
                s[i-1-l]=s[l];
                flaa=1;
            }
        }
            //GAME BEGINS FOR EVEN DIGITS.
        else if(flaa==0&&i%2==0&&s[l]!=s[i-l-1])
        {
            if(s[j/2-1]!='9'&&s[l]<s[j-l-1])
            {
                ++s[j/2-1];
                flaa=1;
            }
            //flag on, for even digits, mid-1!=9
            else if(s[j/2-1]=='9'&&s[l]<s[j-l-1])
            {
                s[j/2-1]='0';
                flaa=1;
                j=j/2-1;
                while(j!=l-1)
                {
                    if(s[j]=='9')
                    {
                        s[j]='0';
                        --j;
                    }
                    else
                    {++s[j];   break;}
                }
                j=i;
            }
            //flag on, for even digits when mid-1==9 & continue increasing digits on left.
            else if(s[l]>s[i-1-l])
            {
                s[i-1-l]=s[l];
                flaa=1;
            }
        }
        if(flaa==1||l==0)
        {
            while(i)
            {
                s[i-1]=s[j-i];
                --i;
            }
            break;
        }
        --l;
    }
    
    printf("%s\n",s);
    flaa=0;
}
return 0;

}

  • created

    May '18
  • last reply

    Jun '18
  • 1

    reply

  • 781

    views

  • 2

    users

  • 2

    links