Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int answer; //ответ   
  8.     //int N; //размерность доски
  9.     int indI, indJ; // конечные индексы на шахматной доске
  10.     int count1, count2, count3; // счетчик переходов по шахматной доске
  11.     int i1, j1, i2, j2, i3, j3; // исходные (начальные) индексы на шахматной доске
  12.  
  13.     //cin >> N;
  14.     cin >> i1 >> j1 >> indI >> indJ;
  15.  
  16.     i3 = i2 = i1;
  17.     j3 = j2 = j1;
  18.     count1 = count2 = count3 = 0;
  19.  
  20.     cout << i1 << "***" << j1 << endl;
  21.     cout << i2 << "***" << j2 << endl;
  22.     cout << i3 << "***" << j3 << endl;
  23.  
  24.     // ЭТО МИНИМАЛЬНЫЙ ПУТЬ (ПО ДИАГОНАЛЕ)
  25.     do {
  26.         if (i1 > indI)
  27.             i1--;
  28.         else if (i1 < indI)
  29.             i1++;
  30.  
  31.         if (j1 > indJ)
  32.             j1--;
  33.         else if (j1 < indJ)
  34.             j1++;
  35.  
  36.         count1++;
  37.     } while (i1 != indI || j1 != indJ);
  38.  
  39.     // ЭТО ПУТЬ ПО ОРТОГОНАЛИ ВНИЗ-ВВЕРХ
  40.     do {
  41.         if (i2 > indI) {
  42.             i2--;
  43.             count2++;
  44.         }
  45.         else if (i2 < indI) {
  46.             i2++;
  47.             count2++;
  48.         }                  
  49.     } while (i2 != indI);
  50.     // ЭТО ПУТЬ ПО ОРТОГОНАЛИ ВЛЕВО-ВПРАВО
  51.     do {
  52.         if (j2 > indJ) {
  53.             j2--;
  54.             count2++;
  55.         }
  56.         else if (j2 < indJ) {
  57.             j2++;
  58.             count2++;
  59.         }
  60.     } while (j2 != indJ);
  61.  
  62.     // ЭТО ПУТЬ ПО ОРТОГОНАЛИ ВЛЕВО-ВПРАВО
  63.     do {
  64.         if (j3 > indJ) {
  65.             j3--;
  66.             count3++;
  67.         }
  68.         else if (j3 < indJ) {
  69.             j3++;
  70.             count3++;
  71.         }
  72.     } while (j3 != indJ);
  73.     // ЭТО ПУТЬ ПО ОРТОГОНАЛИ ВНИЗ-ВВЕРХ
  74.     do {
  75.         if (i3 > indI) {
  76.             i3--;
  77.             count3++;
  78.         }
  79.         else if (i3 < indI) {
  80.             i3++;
  81.             count3++;
  82.         }
  83.     } while (i3 != indI);
  84.    
  85.     // ПОДСЧЕТ
  86.     answer = 1;
  87.     if (count1 == count2 || count1 == count3) {
  88.         answer++;
  89.         if (count2 == count3)
  90.             answer++;
  91.     }
  92.  
  93.     cout << count1 << "__" << count2 << "__" << count3 << endl;
  94.     cout << answer;
  95.  
  96.     _getch();
  97.     return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement