N
N
Nubik2014-06-08 22:13:30
C++ / C#
Nubik, 2014-06-08 22:13:30

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

2 answer(s)
L
lookid, 2014-06-08
@Nubik

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;

J
jcmvbkbc, 2014-06-08
@jcmvbkbc

if (a==c, b==d)

well done (:
and test for a=1, b=1, c=1, d=2?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question