Scalene Triangle codechef starter 69 problem java solution

 

Problem

Given A, B, and C as the sides of a triangle, find whether the triangle is scalene.

Note:

  • A triangle is said to be scalene if all three sides of the triangle are distinct.
  • It is guaranteed that the sides represent a valid triangle.

Input Format

  • The first line of input will contain a single integer T, denoting the number of test cases.
  • Each test case consists of three space-separated integers A, B, and C — the length of the three sides of the triangle.

Output Format

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

You may print each character of the string in uppercase or lowercase. For example, YESyesYes, and yEs are all considered identical.

Constraints

  • 1 \leq T \leq 100
  • 1 \leq A \le B \le C \leq 10
  • C \lt (A+B)

Sample 1:

Input
Output
4
2 3 4
1 2 2
2 2 2
3 5 6
YES
NO
NO
YES

Explanation:

Test case 1: The side lengths are 2, 3, and 4. Since no two side lengths are equal, the triangle is scalene.

Test case 2: The side lengths are 1, 2, and 2. The sides B and C have the same length. Thus, the triangle is not scalene.

Test case 3: The side lengths are 2, 2, and 2. The sides A, B, and C have the same length. Thus, the triangle is not scalene.

Test case 4: The side lengths are 3, 5, and 6. Since no two side lengths are equal, the triangle is scalene.


Solution:

/* package codechef; // don't place package name! */


import java.util.*;

import java.lang.*;

import java.io.*;

import java.util.Scanner;


/* 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 sc = new Scanner (System.in);

int t = sc.nextInt();

for(int i=0; i<t; i++){

    int n1 = sc.nextInt();

    int n2 = sc.nextInt();

    int n3 = sc.nextInt();

    if(n1==n2 || n1==n3 || n2==n3){

        System.out.println("NO");

    }

    else{

        System.out.println("YES");

    }

}

}

}

CodeChef starters 69

Post a Comment

Previous Post Next Post