[ create a new paste ] login | about

Link: http://codepad.org/pf7SkTkM    [ raw code | fork ]

C++, pasted on Mar 4:
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;


long test,t;

int main()
{
    double AB,AC,BC,cosA,cosB,cosC,x1,x2,x3,y1,y2,y3,a[3],pi;
    pi=2*acos(0.0);
    scanf("%ld",&test);
    for (t=1;t<=test;t++)
    {
        scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);

        AB=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
        BC=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
        AC=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));

        a[0]=AB;
        a[1]=BC;
        a[2]=AC;

        sort(a,a+3);

        if ( a[2]<a[1]+a[0])
        {
            cosA=acos((AB*AB+AC*AC-BC*BC)/(2*AB*AC));
            cosA=(180*cosA)/pi;
            cosB=acos((AB*AB-AC*AC+BC*BC)/(2*AB*BC));
            cosB=(180*cosB)/pi;
            cosC=acos((-AB*AB+AC*AC+BC*BC)/(2*BC*AC));
            cosC=(180*cosC)/pi;

//            printf("%lf %lf %lf\n\n",cosA,cosB,cosC);

            if ( AB==AC || AB==BC || AC==BC )
            {
                if ( fabs(cosA-90)<1e-6 || fabs(cosB-90)<1e-6 || fabs(cosC-90)<1e-6 )
                    printf("Case #%ld: isosceles right triangle\n",t);
                else if ( cosA>90 || cosB>90 || cosC>90 )
                    printf("Case #%ld: isosceles obtuse triangle\n",t);
                else if ( cosA<90 && cosB<90 && cosC<90 )
                    printf("Case #%ld: isosceles acute triangle\n",t);
            }

            else
            {
                if ( fabs(cosA-90)<1e-6 || fabs(cosB-90)<1e-6 || fabs(cosC-90)<1e-6 )
                    printf("Case #%ld: scalene right triangle\n",t);
                else if ( cosA>90 || cosB>90 || cosC>90 )
                    printf("Case #%ld: scalene obtuse triangle\n",t);
                else if ( cosA<90 && cosB<90 && cosC<90 )
                    printf("Case #%ld: isosceles acute triangle\n",t);
            }

        }
        else
            printf ("Case #%ld: not a triangle\n",t);
    }

    return 0;
}


Output:
No errors or program output.


Create a new paste based on this one


Comments: