KNIGHTMV - Editorial

PROBLEM LINKS

Practice
Contest

DIFFICULTY

EASY

EXPLANATION

You just simply need to check that string has the length 5, 1st and 4th symbols are in the range ‘a’…‘h’, 2nd and 5th are in the range ‘1’…‘8’, 3rd symbol is ‘-’. After that you need to check is this a correct knight move which is easy exercise. Also you should be careful with spaces. If you use C++ and start your program with something like this scanf(“%d\n”,&TST) then you get wrong answer because the first string in the test contains only spaces and using this command you simply skip it and the second one starts with one space followed by the correct string. Using this command you skip this first space and analyze the string as correct however it’s not.

SETTER’S SOLUTION

Can be found here.

TESTER’S SOLUTION

Can be found here.

coders of c++, pay attn to diff between <cstdio> and <stdio.h> when using gets().

#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
string s;
cin>>t;
getchar();
while(t–)
{
getline(cin,s);
if((s[0]>=‘a’ && s[0]<=‘h’) && (s[3]>=‘a’ && s[3]<=‘h’) && (s[1]>=‘1’ && s[1]<=‘8’) && (s[4]>=‘1’ && s[4]<=‘8’) && (s[2]==’-’))
{
if(((abs(s[0] - s[3])==1) && (abs(s[1] - s[4])==2)) || ((abs(s[0] - s[3])==2) && (abs(s[1] - s[4])==1)))
cout<<“Yes”<<endl;
else
cout<<“No”<<endl;
}
else
cout<<“Error”<<endl;
}
return(0);
}

what is wrong in this code

//