Contents
Codechef 2017 January Challenge RECTANGL
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
- 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
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
<b>Input:</b> 3 1 1 2 2 3 2 2 3 1 2 2 2 <b>Output:</b> YES YES NO
Solution in Java:
Make sure both pairs are equal in value.
import java.io.*; import java.util.StringTokenizer; class RECTANGL { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); int t = Integer.parseInt(br.readLine()); while(t-- >0) { StringTokenizer str = new StringTokenizer(br.readLine()," "); int a = Integer.parseInt(str.nextToken()); int b = Integer.parseInt(str.nextToken()); int c = Integer.parseInt(str.nextToken()); int d = Integer.parseInt(str.nextToken()); if(a == b ) { if(c == d) { bw.write("YES"+ "\n"); bw.flush(); } else { bw.write("NO"+ "\n");; bw.flush(); } } else if(a==c) { if(b == d) { bw.write("YES"+ "\n"); bw.flush(); } else { bw.write("NO"+ "\n"); bw.flush(); } } else if(a==d) { if(b == c) { bw.write("YES"+ "\n"); bw.flush(); } else { bw.write("NO"+ "\n"); bw.flush(); } } else { bw.write("NO"+ "\n"); bw.flush(); } } } }
Another Question from same challenge:
STRING MERGING CODECHEF JANUARY CHALLENGE
Resolving technical problems:
Solve your technical problems instantly
We provide Remote Technical Support from Monday to Sunday, 7:00PM to 1:00 AM
Mail your problem details at [email protected] along with your mobile numberand we will give you a call for further details. We usually attend your problems within 60 minutes and solve it in maximum 2 days.