This code is not giving correct answers in code chef IDE but going OK with Dev c++

#include <stdio.h>
#include<string.h>
int main(void) {
int t;
scanf("%d",&t);
int m;
for(m=0;m<t;m++)
{
int count=0;
char a[3][3];
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%s",&a[i][j]);
}
}
for(i=1;i<3;i++)
{
for(j=0;j<2;j++)
{
if(a[i][j]==‘l’&&a[i-1][j]==‘l’&&a[i][j+1]==‘l’)
count++;
}
}
if(count>=1)
printf(“YES”);
else
printf(“NO”);
}
}

You seem to like to read characters in the form of strings, why?
there’s a line of scanf("%s",&a[i][j]) in your code, read in a string adds a ‘\0’ character to the end of the string.

what is problem with that??
Actually the problem is when i am giving my own input is it okay, but with the automatic inputs by codechef it is not working.
And i didn’t understand your point where is the mistake in taking the input.
You can look into the actual problem if you want.
Here is the link : https://www.codechef.com/problems/LIFELTD

If you use string format to read characters, you read one line at a time, you understand? I think this is what @loopfree mean.

So,few things that’s wrong with this are:
1.) The output should be “yes” or “no” in lowercase.
2.) there should be a next line in each testcase.
3.) you are reading the character array wrong.
4.) scanf("%c",&a[i][j]), will also give wrong answer, as character specifier doesn’t automatically skip whitespaces. so use scanf(" %c",&a[i][j]), i.e, give a space in %c in scanf.

here’s the correct code:

 #include <stdio.h>
		    #include<string.h>
		     int main(void) {
		int t;
		scanf("%d",&t);
		int m;
		for(m=0;m<t;m++)
		{
		int count=0;
		char a[3][3];
		int i,j;
		for(i=0;i<3;i++)
		{
		for(j=0;j<3;j++)
		{
		scanf(" %c",&a[i][j]);
		}
		}
		for(i=1;i<3;i++)
		{
		for(j=0;j<2;j++)
		{
		if(a[i][j]=='l'&&a[i-1][j]=='l'&&a[i][j+1]=='l')
		count++;
		}
		}
		if(count>=1)
		printf("yes\n");
		else
		printf("no\n");
		}
		}

oh thanks :slight_smile: yes you are correct.

Thank you very much. Now i understood.