KNIGHTMV: Showing wa

#include<stdio.h>
#include<stdlib.h>
int main()
{
unsigned int t;
char str[15];
scanf("%ud",&t);
while(t–)
{
fflush(stdin);
scanf("%s",str);
if((str[0]>=‘a’&&str[0]<=‘h’)&&(str[1]>=‘1’&&str[1]<=‘8’)&&(str[2]==’-’)&&(str[3]>=‘a’&&str[3]<=‘h’)&&(str[4]>=‘1’&&str[4]<=‘8’))
{
if((abs(str[0]-str[3])==2&&abs(str[1]-str[4])==1)||(abs(str[0]-str[3])==1&&abs(str[1]-str[4])==2))
puts(“YES”);
else
puts(“NO”);

	 }
	 else
	  puts("ERROR");
    }
	 return 0;
}

The output format is incorrect.

3 Likes

There are three Errors in your code.

Error 1:
The common Error made by users “gets after scanf”.
Refer these links LINK1,LINK2 to know more behind it.
I had Resolved it replacing scanf with gets and then parsing the input testcase string to Integer using atoi function.

Error 2:The output format is not the same as mentioned in problem statement.
Replace “YES”,“NO”,“ERROR” by “Yes” ,“No”, “Error” as its a correct o/p format.

Error 3:You Missed the condition -***“The string represents the correct pair of cells on the chess board if it composed of 5 characters”*** .

I have removed all three bugs that i pointed out and the following Corrected CODE WILL GET ACCEPTED .

	#include<stdio.h>
	#include<stdlib.h>
	#include <string.h>
	int main()
	{ 
		unsigned int t; 
		char str[15];
		char kases[6];
		gets(kases);
		t=atoi(kases);
		while(t--) 
		{
			fflush(stdin);
			gets(str);
			if((strlen(str)==5) && (str[0]>='a'&&str[0]<='h')&&(str[1]>='1'&&str[1]<='8')&&(str[2]=='-')&&(str[3]>='a'&&str[3]<='h')&&(str[4]>='1'&&str[4]<='8')) 
			{ 
				if((abs(str[0]-str[3])==2&&abs(str[1]-str[4])==1)||(abs(str[0]-str[3])==1&&abs(str[1]-str[4])==2)) 
				puts("Yes");
				else puts("No");

			}
			else
				puts("Error");
		}
		return 0;

	}
3 Likes

thanxx…:slight_smile:

please us the code option from toolbar - http://i.imgur.com/ODZlB.png

Can you say whats wrong with this submission http://www.codechef.com/viewsolution/2989381

@rajeevs1992…y r u doing tolower()…if the alphabet is a capital letter it is an error…:stuck_out_tongue: