New Piece Codechef solution

 

Chef's favorite game is chess. Today, he invented a new piece and wants to see its strengths.  From a cell (X,Y), the new piece can move to any cell of the chessboard such that its color is different from that of (X,Y).  The new piece is currently located at cell (A,B). Chef wants to calculate the minimum number of steps required to move it to (P,Q).  Note: A chessboard is an 8×8 square board, where the cell at the intersection of the i-th row and j-th column is denoted (i,j). Cell (i,j) is colored white if i+j is even and black if i+j is odd.






STUDYEVERTHING









#include <iostream>
using namespace std;
int main()
{
  int t;
  cin >> t;
  while (t--)
  {
    int a, b, m, n, p, q, count = 0;
    cin >> a >> b >> p >> q;
    m = a + b;
    n = p + q;

    if (a == p && b == q)
    {
      count = 0;
    }
    else if ((m % 2 == 0 && n % 2 == 0) || (m % 2 != 0 && n % 2 != 0))
    {
      count++;
      count++;
    }
    else if ((m % 2 != 0 && n % 2 == 0) || (m % 2 == 0 && n % 2 != 0))
    {
      count++;
    }
    else
    {
      count = 0;
    }
    cout << count << endl;
  }
}




    


Click on the above button to download the code.



Post a Comment

If you have furthur QUERIES please let us know

Previous Post Next Post