Algorithm


Problem Name: beecrowd | 2313

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2313

Which Triangle

 

By Alexandre A. Melo, IFSC BR Brazil

Timelimit: 1

Given three values, find out if they form a triangle. If so, check if the triangle is scalene, isoceles or equilateral and if it is a triangle rectangle or not.

 

Input

 

Input is given by three integers A,B e C (0 < A,B,C < 105).

 

Output

 

The output must be the one single line containing the string "Invalido" if the input values do not represent a triangle.

If the values can be the sides of a triangle the output must be "Valido-Equilatero" if such triangle is equilateral, "Valido-Escaleno" if it is scalene or "Valido-Isoceles" if it is isoceles. The next line of output must read "Retangulo: S" if the triangle is rectangle or "Retangulo: N" otherwise, as shown in the examples.

 

 

 

Input Samples Output Samples

4 6 2

Invalido

 

 

 

4 3 3

Valido-Isoceles
Retangulo: N

 

 

 

3 4 5

Valido-Escaleno
Retangulo: S

 

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>

int main(void)

{
    int i, j, a[3], temp;

    for (i = 0; i  <  3; ++i)
        scanf("%i", &a[i]);

    for (i = 0; i  <  3-1; ++i)
    {
        for (j = i+1; j  <  3; ++j)
        {
            if (a[j] < a[i])
            {
                temp = a[i];
                a[i] = a[j];
                a[j] = temp;
            }
        }
    }

    if (a[2] >= a[0]+a[1])
        printf("Invalido\n");

    else
    {
        if (a[0] == a[1] && a[1] == a[2])
            printf("Valido-Equilatero\n");

        else if (a[0] != a[1] && a[0] != a[2] && a[1] != a[2])
            printf("Valido-Escaleno\n");

        else
            printf("Valido-Isoceles\n");

        if (a[2]*a[2] == (a[0]*a[0]+a[1]*a[1]))
            printf("Retangulo: S\n");

        else
            printf("Retangulo: N\n");
    }

    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
4 6 2

Output

x
+
cmd
Invalido

#2 Code Example with C++ Programming

Code - C++ Programming


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int a,b,c;
    string ans = "" ;
    cin >> a >> b >> c ;
    if(a+c > b){
    if((a != b and b == c) or ( a == c and a != b) or ( a == b and c != b))
        ans = "Valido-Isoceles";
    else if(a == b and a == c)
        ans = "Valido-Equilatero" ;
    else if(a != b and b != c and a != c)
        ans = "Valido-Escaleno";
    }
    else{
        ans = "Invalido";
    }

    if(ans != "Invalido"){
      if(pow(a,2) == pow(b,2) + pow(c,2) or pow(b,2) == pow(a,2) + pow(c,2) or pow(c,2) == pow(a,2) + pow(b,2))
        cout << ans << endl << "Retangulo: S" << endl ;
       else
        cout << ans << endl << "Retangulo: N" << endl;
    }
    else
        cout << ans << endl;

    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
4 6 2

Output

x
+
cmd
Invalido

#3 Code Example with Javascript Programming

Code - Javascript Programming


var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');
const numbers = lines.shift().split(" ");
numbers.sort((a,b) => a - b).reverse();

const [a, b, c] = numbers
const A = parseFloat(a);
const B = parseFloat(b);
const C = parseFloat(c);

if(A >= B + C){
  console.log("Invalido");
  return;
}

if(A == B && B == C){
  console.log("Valido-Equilatero");
}
else if(A == B || A == C || B == C){
  console.log("Valido-Isoceles");
}

else if(A != B && B != C && C != A){
  console.log("Valido-Escaleno");
}

if(Math.pow(A, 2) == (Math.pow(B,2) + Math.pow(C,2))){
  console.log("Retangulo: S");
}
else{
  console.log("Retangulo: N");
}

Copy The Code & Try With Live Editor

Input

x
+
cmd
4 6 2

Output

x
+
cmd
Invalido

#4 Code Example with Python Programming

Code - Python Programming


A, B, C = input().split()

A = int(A)
B = int(B)
C = int(C)

if(A < B and A < C and B < C):

    a = C
    b = B
    c = A

elif(A < B and A < C and C < B):

    a = B
    b = C
    c = A

elif(B < A and B < C and A < C):

    a = C
    b = A
    c = B

elif(B < A and B < C and C < A):

    a = A
    b = C
    c = B

elif(C < A and C < B and A < B):

    a = B
    b = A
    c = C

elif(C < A and C < B and B < A):

    a = A
    b = B
    c = C

elif(A == B and A < C):

    a = C
    b = A
    c = A

elif(A == B and C < A):

    a = A
    b = A
    c = C

elif(A == C and A < B):

    a = B
    b = A
    c = A

elif(A == C and B < A):

    a = A
    b = B
    c = A

elif(B == C and B < A):

    a = A
    b = B
    c = B

elif(B == C and A < B>:

    a = B
    b = A
    c = B

else:

    a = A
    b = B
    c = C


if(a >= b + c):

    print("Invalido")
    
    exit()

elif(a == b and b == c):

    print("Valido-Equilatero")

elif(a == b or a == c or b == c):

    print("Valido-Isoceles")

else:

    print("Valido-Escaleno")


if(((a * a) == b * b + c * c) == True):

    print("Retangulo: S")

else:

    print("Retangulo: N")
Copy The Code & Try With Live Editor

Input

x
+
cmd
4 6 2

Output

x
+
cmd
Invalido
Advertisements

Demonstration


Previous
#2312 Beecrowd Online Judge Solution 2312 Medal Table Solution in C, C++, Java, Js and Python
Next
#2315 Beecrowd Online Judge Solution 2315 Easy Difference Between Dates Solution in C, C++, Java, Js and Python