Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
You are given a standard 8×8 chessboard which has exactly 2 rooks on it and no other pieces. The rows are numbered 1 to 8 from bottom to top, and the columns are numbered 1 to 8 from left to right. The cell at the intersection of the i-th column and j-th row is denoted (i,j).
Given the initial positions of the rooks in the form of coordinates ((X1,Y1) and (X2,Y2), you need to tell whether the 2 rooks currently attack each other or not. Assume, each square can contain at most one piece.
Rooks can only travel in straight lines along the row or column they are placed at, and can’t jump over other pieces. For a more detailed explanation of the moves of rooks, along with images, please click here.
For each test case, output on a single line YES
(without quotes) if the rooks attack each other, and NO
otherwise.
You may print each character of the string in uppercase or lowercase (for example, the strings YeS
, YEs
, yes
and yeS
will all be treated as identical).
Input:
3
1 2 5 2
1 2 1 5
1 1 8 8
Output:
YES
YES
NO
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner in = new Scanner(System.in);
int t = in.nextInt();
while(t-- >0){
int x1 = in.nextInt();
int y1 = in.nextInt();
int x2 = in.nextInt();
int y2 = in.nextInt();
if(x1==x2 || y1==y2){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}
}
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
void sol(){
int x1,x2,y1,y2;
cin>>x1>>y1>>x2>>y2;
cout<<((x1==x2 || y1==y2)? "YES":"NO")<<endl;
}
int main(){
ios_base::sync_with_stdio (false);
cin.tie(NULL);cout.tie(NULL);
int t;
cin>>t;
while(t--)
sol();
return 0;
}
# cook your dish here
t = int(input())
for i in range(0,t):
x1,y1,x2,y2 = map(int,input().split())
if x1==x2 or y1==y2: print ("YES")
else: print("NO")
In our experience, we suggest you solve this Two Rooks CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.
If you are stuck anywhere between any coding problem, just visit Queslers to get the Two Rooks CodeChef Solution
I hope this Two Rooks CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.
This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.
Keep Learning!
More Coding Solutions >>