[Solved] Perfect Trio STARTERS 71 CodeChef

Chef defines a group of three friends as a perfect group if the age of one person is equal to the sum of the age of remaining two people.

Given that, the ages of three people in a group are A, B,A,B, and CC respectively, find whether the group is perfect.

Input Format
  • The first line of input will contain a single integer TT, denoting the number of test cases.
  • Each test case consists of three space-separated integers A, B,A,B, and CC β€” the age of the three members of group.
Output Format

For each test case, output on a new line, YES, if the group is perfect, and NO otherwise.

You may print each character in uppercase or lowercase. For example, the strings YESyesYes, and yES are considered identical.

Constraints
[Solved] Perfect Trio STARTERS 71 CodeChef
Sample 1:

Input

4
10 20 30
23 51 17
44 21 23
30 30 30

Output

YES
NO
YES
NO
Explanation:

Test case 11: The sum of age of first and second person is equal to that of the third person. Thus, the group is perfect.

Test case 22: There exists no member in the group such that the age of one person is equal to the sum of the age of remaining two people. Thus, the group is not perfect.

Test case 33: The sum of age of second and third person is equal to that of the first person. Thus, the group is perfect.

Test case 44: There exists no member in the group such that the age of one person is equal to the sum of the age of remaining two people. Thus, the group is not perfect.

Solution

/* 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 sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-->0){
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            // sauravhathi
            if(a==b+c || b==a+c || c==a+b){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }
        }
	}
}

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

πŸ“Œ Nodejs and Android 😎
πŸ“Œ Java

Articles: 444

Leave a Reply

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