URI Online Judge Solution 1045 Triangle Types Solution in C, C++, Java, Python and C# - Online Judge Solution

Latest

It is a free Online judges problems solution list. Here you can find UVA online Judge Solution, URI Online Judge Solution, Code Marshal Online Judge Solution, Spoz Online Judge Problems Solution

Wednesday, July 12, 2017

URI Online Judge Solution 1045 Triangle Types Solution in C, C++, Java, Python and C#

URI Online Judge Solution 1045 Triangle Types Solution in C, C++, Java, Python and C#

URI Online Judge Solution 1045 Triangle Types | Beginner
URI Problem Link - https://www.urionlinejudge.com.br/judge/en/problems/view/1045

Problem Name: 1045 Triangle Types
Problem Number : URI - 1045 Triangle Types
Online Judge : URI Online Judge Solution
Category: Beginner
Solution Language : C,C plus plus, java, python, c#(c sharp)

URI Online Judge Solution 1045 Triangle Types Solution in C, C++, Java, Python and C#


URI 1045 Triangle Types Code in C / URI 1045 solution in C:

#include <stdio.h>

int main()

{

    double a, b, c, temp;

    scanf("%lf %lf %lf", &a, &b, &c);

    if (a < b)

    {
        temp = a;
        a = b;
        b = temp;
    }

    if (b < c)

    {
        temp = b;
        b = c;
        c = temp;
    }

    if (a < b)
    {
        temp = a;
        a = b;
        b = temp;
    }

    if (a >= b + c)

    {
        printf("NAO FORMA TRIANGULO\n");
    }

    else if (a * a == b * b + c * c)

    {
        printf("TRIANGULO RETANGULO\n");
    }

    else if (a * a > b * b + c * c)

    {
        printf("TRIANGULO OBTUSANGULO\n");
    }

    else if (a * a < b * b + c * c)

    {
        printf("TRIANGULO ACUTANGULO\n");
    }

     

    if (a == b && b == c)

    {
        printf("TRIANGULO EQUILATERO\n");
    }

    else if (a == b || b == c)

    {
        printf("TRIANGULO ISOSCELES\n");
    }

    return 0;

}


URI 1045 Triangle Types Code in C++ / URI 1045 solution in CPP:

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
 float x;
 vector<float> v;

 for (int i = 0; i < 3; ++i)
 {
  cin >> x;
  v.push_back(x);
 }

 sort(v.begin(), v.begin() + 3);
 float a, b, c;

 c = v[0];
 b = v[1];
 a = v[2];

 if(a >= (b + c)){
  cout << "NAO FORMA TRIANGULO" << endl;
 }else{

  if(a*a == (b*b + c*c)){
   cout << "TRIANGULO RETANGULO" << endl;
  }else if(a*a > (b*b + c*c)){
   cout << "TRIANGULO OBTUSANGULO" << endl;
  }else{
   cout << "TRIANGULO ACUTANGULO" << endl;
  }

  if(a == b && b == c){
   cout << "TRIANGULO EQUILATERO" << endl;
  }

  if((a == b && a != c) || (b == c && b != a) || (c == a && c != b)){
   cout << "TRIANGULO ISOSCELES" << endl;
  }
 }

 return 0;
}


URI 1045 Triangle Types Code in java/ URI 1045 solution in Java:

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

public class Main {
 
    public static void main(String[] args) throws IOException {
 
        double A, B, C;
  Scanner input =new Scanner(System.in);
  A = input.nextDouble();
  B = input.nextDouble();
  C = input.nextDouble();
  double tempA = Math.max(A, Math.max(B, C));
  double tempB = 0;
  double tempC = 0;
  
  if (tempA == A) {
   tempB =Math.max(B, C);
   tempC =Math.min(B, C);
  }
  if (tempA == B) {
   tempB =Math.max(A, C);
   tempC =Math.min(A, C);
  }
  if (tempA == C) {
   tempB =Math.max(B, A);
   tempC =Math.min(B, A);
  }
  //------------------------------
  if (tempA >= (tempB + tempC)) {
   System.out.print("NAO FORMA TRIANGULO\n");
   
  }else if (tempA*tempA > ((tempB*tempB)+(tempC*tempC))) {
   System.out.print("TRIANGULO OBTUSANGULO\n");
  }
  if (tempA*tempA == ((tempB*tempB)+(tempC*tempC))) {
   System.out.print("TRIANGULO RETANGULO\n");
  }

  if (tempA*tempA < ((tempB*tempB)+(tempC*tempC))) {
   System.out.print("TRIANGULO ACUTANGULO\n");
  }
  if ((tempA == tempB) &&(tempA == tempC)) {
   System.out.print("TRIANGULO EQUILATERO\n");
  }
  if (((tempA == tempB) &&(tempA != tempC)) || ((tempA == tempC) &&(tempA != tempB)) || ((tempB == tempC) &&(tempB != tempA)) ) {
   System.out.print("TRIANGULO ISOSCELES\n");
  }
 
    }
 
}


URI 1045 Triangle Types Code in Python / URI 1045 solution in Python:


URI Solution 1045 Triangle Types Code / URI 1045 solution in  C# (C Sharp):




Demonstration:

Just implement this in coding. Since having any problem just put a comment below. Thanks



Tags: URI Online Judge Solution, URI OJ Solution list, URI Problems Solution, URI solver, URI all problem solution list, URI Triangle Types code in C, URI 1045 Triangle Types code in C++, URI Triangle Types solution in C, URI solution, URI 1045 solution in C,URI 1045 solution in C++-CPP, URI 1045 Triangle Types solution in C# (C sharp),URI 1045 solution in Java,URI 1045 Triangle Types solution in Python,

1 comment:

  1. one thing i don't get it why you using if(a < b)
    {
    temp = a;
    a = b;
    b = temp;
    }
    double time .. can you please tell me please.

    ReplyDelete