Lapindromes

this is my c code for the given problem
can anyone please tell me why this code is wrong

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        char *a, *b,*c,p;
        a=(char*)calloc(1001,sizeof(char));
        scanf("%s",a);
        int l,mid,i,j,ans;
        ans=1;
        l=strlen(a);
        mid=l/2;
        b=(char*)calloc(l/2,sizeof(char));
        c=(char*)calloc(l/2,sizeof(char));
        if(l%2)
        {
            for(i=0;i<mid;i++)
                b[i]=a[i];
            for(i=mid+1;i<l;i++)
                c[i-mid-1]=a[i];
        }
        else
        {
            for(i=0;i<mid;i++)
                b[i]=a[i];
            for(i=mid;i<l;i++)
                c[i-mid]=a[i];
        }
        for(i=0;i<mid;i++)
        {
            p=b[i];
            for(j=0;j<mid;j++)
                if(c[j]==p)
                {
                    c[j]='\0';
                    break;
                }
        }
        for(i=0;i<mid;i++)
            if(c[i]!='\0')
                ans=0;
        if(ans)
            printf("yes");
        else
            printf("no");
    }
}

Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

Edit:

Hmmm … how come I can edit the CodeChef-DSA-learners posts? Oh well :slight_smile:

2 Likes

I didn’t get what you are trying to say
I had just submitted the code but it shows wrong ans

Most immediate problem: You are outputting yes and no, but you should be outputting YES and NO.

Edit:

You’re also not outputting a linebreak after each answer:

 printf("\n");
3 Likes

That’s because any post with that tag is considered a wiki.
It doesn’t become a wiki if you change it though after it’s posted.
I made mine a wiki, and now you can edit this post.

Edit: (by ssjgz) - wow - so I can - thanks :slight_smile:

3 Likes

okk
thanks

how to make it a wiki??

I think you have to be active for 100 days and get 100 likes and give 50 likes before you get that option. But If you tag a post with DSA learner’s, Then it’s automatically a wiki.

2 Likes

okk
thanks a lot
I got it submitted

1 Like