Answer the question
In order to leave comments, you need to log in
How to fail a knight's move?
Task: https://acmp.ru/index.asp?main=task&id_task=6
Problem: it crashes on the 10th test, I break my head, I don't understand why.
The code:
string n;
cin >> n;
string a = "ABCDEFGH";
int i1 = n[1] - '0';
int i2 = n[4] - '0';
char c1 = n[0];
char c2 = n[3];
int iN = abs(i1-i2);
int cN = abs(find(a.begin(), a.end(), c1) - find(a.begin(), a.end(), c2));
bool isCharactersWrong = find(a.begin(), a.end(), c1) == a.end() || find(a.begin(), a.end(), c2) == a.end();
bool isNumbersWrong = i1>8 || i2>8 || i1<=0 || i2<=0;
if (isNumbersWrong || isCharactersWrong) {
cout << "ERROR" << endl;
}
else if ((iN==2 && cN==1) || (iN==1 && cN==2)) {
cout << "YES" << endl;
}
else {
cout << "NO" << endl;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question