Thursday, 17 November 2016

Solution of URI 2313 :: Which Triangle


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>

int max(int a, int b)
{
    return ((a>b) ? a: b);
}
int min(int a, int b)
{
    return  (a<b) ? a: b;
}
int main()
{
    long long int a, b, c, x, y, z;
    scanf("%lld %lld %lld", &a, &b, &c);
    x = max(a, max(b, c));
    z = min(a, min(b, c));
    y = a + b + c - x - z;
    if(x >= y+z) printf("Invalido\n");
    else
    {
        if(x==y && y==z) printf("Valido-Equilatero\n");
        else if(x!=y && y!=z && x!=z) printf("Valido-Escaleno\n");
        else printf("Valido-Isoceles\n");
        if(x*x == (y*y + z*z)) printf("Retangulo: S\n");
        else printf("Retangulo: N\n");
    }
    return 0;
}

3 comments:

  1. #include
    int main ()
    {

    int A,B,C;
    scanf("%d%d%d", &A, &B, &C);

    if ((A+B>C) && (A+C>B) && (C+B>A))
    {
    if((A==B) && (B==C))
    printf ("Valido-Equilatero\n");
    else if ((A!=B) && (B!=C) && (C!=A))
    printf ("Valido-Escaleno\n");
    else if ((A==B && B!=C) || (B==C && C!=A) || (C==A && A!=B))
    printf ("Valido-Isoceles\n");
    if ((C*C)==(A*A)+(B*B))
    printf ("Retangulo: S\n");
    else
    {
    printf ("Retangulo: N\n");
    }
    }
    else
    {
    printf ("Invalido\n");
    }

    return 0;
    }

    ReplyDelete
  2. What is wrong with my answer?

    ReplyDelete
  3. #include
    int main()
    {
    long long int a,b,c;

    scanf("%lld%lld%lld",&a,&b,&c);
    if(a+b<=c || a+c<=b || b+c<=a) printf("Invalido\n");
    else
    {
    if(a==b && b==c)printf("Valido-Equilatero\n");
    else if(a!=b || b!=c || a!=c)printf("Valido-Isoceles\n");

    if(a*a==b*b+c*c || b*b==a*a+c*c || c*c==a*a+b*b)printf("Retangulo: S\n");
    else printf("Retangulo: N\n");
    }
    return 0;
    }
    // What is wrong with my answer?

    ReplyDelete

Note: only a member of this blog may post a comment.