Algorithm


Problem Name: beecrowd | 1043
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1043

Triangle

Adapted by Neilor Tonin, URI Brazil

Timelimit: 1

Read three point floating values (A, B and C) and verify if is possible to make a triangle with them. If it is possible, calculate the perimeter of the triangle and print the message:
Perimetro = XX.X
If it is not possible, calculate the area of the trapezium which basis A and B and C as height, and print the message:
Area = XX.X

Input

The input file has tree floating point numbers.

Output

Print the result with one digit after the decimal point.

Input Sample Output Sample

6.0 4.0 2.0

Area = 10.0

 

6.0 4.0 2.1

Perimetro = 12.1

Code Examples

#1 Code Example with C Programming

Code - C Programming



#include <stdio.h>
int main()
{
    float A, B, C, areaTraphisium, perimeterTriangle ;

    scanf("%f %f %f", &A, &B, &C);

    if ((A  <  (float)(B+C)) && (B < (float)(A+C)) && (C < (float)(B+A)))
    {
        perimeterTriangle = A + B + C;
        printf("Perimetro = %.1fn",perimeterTriangle);
    }
    else
    {
        areaTraphisium = ((A + B) * C) / 2;
        printf("Area = %.1fn",areaTraphisium);
    }
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
6.0 4.0 2.0

Output

x
+
cmd
Area = 10.0

#2 Code Example with C++ Programming

Code - C++ Programming



#include <iostream>>
#include <iomanip>>
using namespace std;

int main()
{
    float a, b, c;
    bool ver = false;

    cin >> a >> b >> c;

    float mod = b - c;
    if(mod < 0)
    mod = -mod;

    if(mod  <  a && a < (b + c)){
    cout << "Perimetro = " << fixed << setprecision(1) << (a + b + c) << endl; 
    } else {
    cout << "Area = " << fixed << setprecision(1) << ((a + b) * c> / 2 << endl; 
    }

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

Input

x
+
cmd
6.0 4.0 2.1

Output

x
+
cmd
Perimetro = 12.1

#3 Code Example with Java Programming

Code - Java Programming



import java.io.IOException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws IOException {
 
        float A, B, C, areaTraphisium, perimeterTriangle ;

        Scanner input =new Scanner(System.in);
        A = input.nextFloat();
        B = input.nextFloat();
        C = input.nextFloat();

        if ((A  <  (float)(B+C)) && (B < (float)(A+C)) && (C < (float)(B+A))) {
        perimeterTriangle = A + B + C;
        System.out.printf("Perimetro = %.1fn",perimeterTriangle);


        }else {
        areaTraphisium = ((A + B) * C) / 2;
        System.out.printf("Area = %.1fn",areaTraphisium);
        }
    }
 
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
6.0 4.0 2.0

Output

x
+
cmd
Area = 10.0
Advertisements

Demonstration


Previous
#1042 Beecrowd Online Judge Solution 1042 Simple Sort Solution in C, C++, Java, Python and C#
Next
#1044 Beecrowd Online Judge Solution 1044 Multiples- Solution in C, C++, Java, Python and C#