why am i getting NO for all the test cases?

//lapindromes

#include<stdio.h>
#include<string.h>
int count(char str[],char ch)
{
int count=0,k=0;
while(str[k]!='\0')
{
if(str[k]==ch)
count++;
k++;
}
return count;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int i,j,yes=1;
char s[1000];
scanf("%s",s);
char str1[501],str2[501];
int n=strlen(s);
if(n%2==0)
    {
        for(i=0;i<n/2;i++)
            str1[i]=s[i];
        for(j=n/2;s[j]!='\0';j++)
            str2[j]=s[j];
    }
else
{
    for(i=0;i<n/2;i++)
        str1[i]=s[i];
        for(j=n/2+1;s[j]!='\0';j++)
            str2[j]=s[j];
}
for(i=0;i<strlen(str1);i++)
{
    if(count(str1,str1[i])!=count(str2,str1[i]))
    {
        yes=0;
        break;
    }
}
if(yes)
    printf("YES\n");
else
    printf("NO\n");
}
return 0;
}

The first problem with your code is that you are using str1 and str2 two separate character arrays where you are not explicitly writing ‘\0’ at the end to mark the ending of the string.

The second problem with your code is that you are filling str2 string from character n/2 but your count method is always running from 0.

1 Like

after doing these corrections the code is running for all the test cases…but still it’s not being accepted by codechef!