NOJ1013 三角形判断(模拟)

10 篇文章 0 订阅

三角形判断

时间限制(普通/Java) :  1000 MS/ 3000 MS          运行内存限制 : 65536 KByte
总提交 : 2731            测试通过 : 453 

比赛描述

给定三条边的长度,判断能否组成三角形,如果可以,判断三角形的形状。



输入

一组数据,每行三个实数,在(0,10]之间,精确到小数点后第四位。最后以0 0 0表示结束。

输出

根据每行的数据判断,如果不能组成三角形,则输出“Not a triangle”;如果是“等腰三角形”,则输出“Isosceles triangle”;如果是“直角三角形”,则输出“Right triangle”;如果是“等腰直角三角形”,则输出“Isosceles right triangle”;如果是“等边三角形”,则输出“Equilateral triangle”;否则,输出“General triangle”。最后输出一行“End”。

样例输入

1.4142 1.4142 2
1.0000 4.0000 5.0000
0 0 0

样例输出

Isosceles right triangle
Not a triangle
End


同样是学c语言时候做的题~ 一年前的我还不知道代码规范是什么。。


AC代码:


#include<iostream>  
#include<cstdio>  
#include<algorithm>  
#include<cmath>  
using namespace std;  
  
int Isosceles(double a,double b,double c);  
int Right(double a,double b,double c);  
int istriangle(double a,double b,double c)  
{  
    if(a<1e-3) return 0;  
    if(a+b-c>1e-3)  
        return 1;  
    return 0;  
}  
  
int Equilateral(double a,double b,double c)  
{  
    if(fabs(a-c)<1e-3)  
        return 1;  
    return 0;  
}  
  
int IsRight(double a,double b,double c)  
{  
    double aa=pow(a*1.0,2),bb=pow(b*1.0,2),cc=pow(c*1.0,2);  
    if(fabs(aa+bb-cc)<1e-3&&(fabs(a-b)<1e-3))  
        return 1;  
    return 0;  
}  
  
int Right(double a,double b,double c)  
{  
    if(!(fabs(a-b)<1e-3))  
    {  
        double aa=pow(a*1.0,2),bb=pow(b*1.0,2),cc=pow(c*1.0,2);  
        if(fabs(aa+bb-cc)<1e-3)  
            return 1;  
    }  
    return 0;  
}  
  
int Isosceles(double a,double b,double c)  
{   if(fabs(a-b)<1e-3||fabs(c-b)<1e-3) return 1;  
    return 0;  
}  
  
  
int main()  
{  
    double temp[5];  
    int sum;  
    while(1)  
    {  
        scanf("%lf%lf%lf",&temp[0],&temp[1],&temp[2]);  
        if(temp[0]==0) break;  
        sum=0;  
        //sort  
        sort(temp,temp+3);  
        if(istriangle(temp[0],temp[1],temp[2])==0)  
            printf("Not a triangle\n");  
        else  
        {  
            if(Equilateral(temp[0],temp[1],temp[2])==1)  
            {  
                sum++;  
                printf("Equilateral triangle\n");  
            }  
            else  
            {  
                if(IsRight(temp[0],temp[1],temp[2])==1)  
                {  
                    sum++;  
                    printf("Isosceles right triangle\n");  
                }  
                else  
                {  
                    if(Isosceles(temp[0],temp[1],temp[2])==1)  
                    {  
                        sum++;  
                        printf("Isosceles triangle\n");  
                    }  
  
                    else  
                    {  
                        if(Right(temp[0],temp[1],temp[2])==1)  
                        {  
                            sum++;  
                            printf("Right triangle\n");  
                        }  
                    }  
                }  
            }  
  
            if(sum==0)  
            {  
                printf("General triangle\n");  
            }  
        }  
    }  
    printf("End");  
    return 0;  
}   



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值