PALIN: provide me some corner cases where my program is falling..


 #include< stdio.h >
 #include< string.h >
 int comp(char a[],char s[],int l)
 {
	int i;
	for(i=l/2 ; i < l ; i++)
	if(a[i] < s[i])
	  return 0;
	else if(a[i] > s[i])
	  return 1;
 }
 int compcheck(char a[],char s[],int l)
 {
	int i;
	for(i=0 ;i < l ; i++)
	if(a[i] < s[i])
	   return 0;
	else if(a[i] > s[i])
	   return 1;
}
int ninecheck(char a[],int l)
{
	int i,nine=0;
	for(i=0 ;i < l ; i++)
		if(a[i]=='9')
			++nine;
	if(nine==l)
		return 1;
	else
		return 0;
  }
void mequal(char a[],char s[],int l)
{
	int i,j,k,f;
	if(l%2==0)
	{
		i=(l)/2-1;
		j=(l-1)/2+1;
		f=comp(a,s,l);
		while(!f)
		{
			if(a[i]=='9' && a[j]=='9')
			{
				a[i--]='0';
				a[j++]='0';	
				++a[i];
				++a[j];
				--i;
				++j;
				f=compcheck(a,s,l);
			}
			else if(!(a[i]=='9' && a[j]=='9'))
			{
				a[i]=a[i]+1;
				a[j]=a[j]+1;
				f=1;
			}
			else
				f=1;
		}
	}
	else
	{
		k=(l-1)/2;
		{
			if(a[k]!='9')
				a[k]+=1;
			else
			{
				a[k]='0';
				i=l/2-1;
				j=(l-1)/2+1;
				f=comp(a,s,l);
				while(!f)
				{
					if(a[i]=='9' && a[j]=='9')
					{
						a[i--]='0';
						a[j++]='0';	
						++a[i];
						++a[j];
						--i;
						++j;
						f=compcheck(a,s,l);
					}
					else if(!(a[i]=='9' && a[j]=='9'))
					{
						a[i]=a[i]+1;
						a[j]=a[j]+1;
						f=1;
					}
					else
						f=1;
				}			
			}
		}
	}

}
int main()
{
	long long int t,l,i,k;
	scanf("%lld ",&t);
	while(t--)
	{
		char s[1000010],a[1000010];
		gets(s);
		k=0;
		long long int f1=1;
		l=strlen(s);
		i=0;
		while(f1)
		{
			if(s[k]!='0')
			{
				f1=0;
				break;
			}
			else
			{
				++k;
			}
		}
		for(i=0;i < l-k;i++)
		{
			s[i]=s[i+k];
		}
		s[l-k]='\0';
		long long int f,nine;
		l=strlen(s);
		if(k==l)
		{
			s[0]='0';
			s[1]='\0';
		}
		strcpy(a,s);
		for(i=0;i < l/2;i++)
			a[l-1-i]=a[i];
		f=comp(a,s,l);
		nine=ninecheck(a,l);
		if(f==1)
			puts(a);
		else if(nine==1)
		{
			a[0]=a[l]='1';
			for(i=1;i < l;i++)
				a[i]='0';
			a[l+1]='\0';
			puts(a);
		}
		else if(f==0)
		{
			mequal(a,s,l);	
			puts(a);
		}
	}
return 0;
}

You dont need to post your entire code, just give the link.

princelegalos i’ll do it from next time… could you plz help me out…

Your code does not give any output if the given number itself is a palindrome.Check for 808,121,…

1 Like

thanks for figuring it out … :slight_smile:

http://www.codechef.com/viewsolution/4133022
still wa … any corner case for this one …