Rectangle | CodeChef Solution

Hello coders, today we are going to solve Rectangle CodeChef Solution whose Problem Code is RECTANGL.

Rectangle

Task

You are given four integers a, b, c and d. Determine if there’s a rectangle such that the lengths of its sides are a, b, c and d (in any order).

Input Format

  • The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
  • The first and only line of each test case contains four space-separated integers a, b, c and d.

Output Format

For each test case, print a single line containing one string “YES” or “NO”.

Constraints

  • 1 ≤ T ≤ 1,000
  • 1 ≤ a, b, c, d ≤ 10,000

Subtasks

Subtask #1 (100 points): original constraints

Example

Sample Input

3
1 1 2 2
3 2 2 3
1 2 2 2

Sample Output

YES
YES
NO

Solution – Rectangle | CodeChef Solution

C++

#include <iostream>
#include <string>
#include <cmath>
using namespace std;

int main(){
        int t, a, b, c, d;
        cin >> t;
        while (t--){
                cin >> a >> b >> c >> d;
                if ((a == b && c == d) || (a == c && b == d) || (a == d && b == c))
                        printf("%s\n", "YES");
                else
                        printf("%s\n", "NO");
        }
        return 0;
}

Python

# cook your dish here
for _ in range(int(input())):
    a, b, c, d = map(int, input().split())
    if a==b and c==d:
        print("YES")
    elif a==c and b==d:
        print("YES")
    elif a==d and b==c:
        print("YES")
    else:
        print("NO")

Java

/* 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
	{
		// your code goes here
		 Scanner input=new Scanner(System.in);
        int T=input.nextInt();
        int a[]=new int[T];
        int b[]=new int[T];
        int c[]=new int[T];
        int d[]=new int[T];
        for(int i=0;i<T;i++){
            a[i]=input.nextInt();
            b[i]=input.nextInt();
            c[i]=input.nextInt();
            d[i]=input.nextInt();
            if(a[i]+b[i]==c[i]+d[i]){
                System.out.println("YES");
            }
            else if(a[i]+c[i]==b[i]+d[i]){
                System.out.println("YES");
            }
            else if(a[i]+d[i]==b[i]+c[i]){
                System.out.println("YES");
            }
            else{
                System.out.println("NO");
            }

        }
	}
}

Disclaimer: The above Problem (Rectangle) is generated by CodeChef but the Solution is Provided by CodingBroz. This tutorial is only for Educational and Learning Purpose.

Leave a Comment

Your email address will not be published. Required fields are marked *