Answer the question
In order to leave comments, you need to log in
How to limit the numbers a,b,c,d using the array dimension from 1 to 8???
Task:
The field of the chessboard is determined by a pair of numbers (a,b), each from 1 to 8, the first number is the column number, the second is the row number. 2 cells are given. Determine if the rook can get from the first cell to the second in 1 move?
Prog:
#include <iostream>
using namespace std;
int main()
{
int a, b, c, d;
cout « "Введите номер строки\n";
cin » a;
cout « "Введите номер столбца\n";
cin » b;
cout « "Введите строку другой клетки\n";
cin » c;
cout « "Введите столбец другой клетки\n";
cin » d;
if (a==c||b==d)
cout « "Yes\n";
else
cout « "No\n";
system ("PAUSE");
return 0;
}
Answer the question
In order to leave comments, you need to log in
boat
Checks:
1) that the cell lies on one vertical or one horizontal O(1)
2) that no one blocks the path to this cell O(n)
Total:
enum {OK, FAIL} States;
States state = OK;
check(state);
return state;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question