Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- using namespace std;
- int main() {
- int answer; //ответ
- //int N; //размерность доски
- int indI, indJ; // конечные индексы на шахматной доске
- int count1, count2, count3; // счетчик переходов по шахматной доске
- int i1, j1, i2, j2, i3, j3; // исходные (начальные) индексы на шахматной доске
- //cin >> N;
- cin >> i1 >> j1 >> indI >> indJ;
- i3 = i2 = i1;
- j3 = j2 = j1;
- count1 = count2 = count3 = 0;
- cout << i1 << "***" << j1 << endl;
- cout << i2 << "***" << j2 << endl;
- cout << i3 << "***" << j3 << endl;
- // ЭТО МИНИМАЛЬНЫЙ ПУТЬ (ПО ДИАГОНАЛЕ)
- do {
- if (i1 > indI)
- i1--;
- else if (i1 < indI)
- i1++;
- if (j1 > indJ)
- j1--;
- else if (j1 < indJ)
- j1++;
- count1++;
- } while (i1 != indI || j1 != indJ);
- // ЭТО ПУТЬ ПО ОРТОГОНАЛИ ВНИЗ-ВВЕРХ
- do {
- if (i2 > indI) {
- i2--;
- count2++;
- }
- else if (i2 < indI) {
- i2++;
- count2++;
- }
- } while (i2 != indI);
- // ЭТО ПУТЬ ПО ОРТОГОНАЛИ ВЛЕВО-ВПРАВО
- do {
- if (j2 > indJ) {
- j2--;
- count2++;
- }
- else if (j2 < indJ) {
- j2++;
- count2++;
- }
- } while (j2 != indJ);
- // ЭТО ПУТЬ ПО ОРТОГОНАЛИ ВЛЕВО-ВПРАВО
- do {
- if (j3 > indJ) {
- j3--;
- count3++;
- }
- else if (j3 < indJ) {
- j3++;
- count3++;
- }
- } while (j3 != indJ);
- // ЭТО ПУТЬ ПО ОРТОГОНАЛИ ВНИЗ-ВВЕРХ
- do {
- if (i3 > indI) {
- i3--;
- count3++;
- }
- else if (i3 < indI) {
- i3++;
- count3++;
- }
- } while (i3 != indI);
- // ПОДСЧЕТ
- answer = 1;
- if (count1 == count2 || count1 == count3) {
- answer++;
- if (count2 == count3)
- answer++;
- }
- cout << count1 << "__" << count2 << "__" << count3 << endl;
- cout << answer;
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement