文章

84

粉丝

408

获赞

31

访问

831.5k

头像
直角三角形(c++)
P1445 北京理工大学机试题
发布于2020年3月7日 11:19
阅读数 14.3k

个人感觉这题有点问题,标准答案似乎忘记判断这个三角形是否满足任意两边之和大于第三边

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
class CPoint{
private:
	int x, y;
public:
	CPoint(){}
	CPoint(int xx, int yy):x(xx),y(yy){}
	~CPoint(){}
	void setvalue(int xx, int yy) {
		x = xx;
		y = yy;
	}
	double operator-(CPoint c);
	CPoint operator=(CPoint c);
};
double CPoint::operator-(CPoint c)
{
	return sqrt((x-c.x)*(x-c.x) + (y-c.y)*(y-c.y));
}
CPoint CPoint::operator=(CPoint c)
{
	return CPoint(c.x, c.y);
}
class CTriangle{
private:
	CPoint A, B, C;		//点 
	double a, b, c;		//边长 
public:
	CTriangle(){}
	CTriangle(CPoint AA, CPoint BB, CPoint CC):A(AA), B(BB), C(CC){
		a = B - C;
		b = A - C;
		c = A - B;
	}
	~CTriangle(){}
	bool isRight();
	double perimeter();
};
bool CTriangle::isRight()
{
	double m = a, n = b, l = c, t;
	if (m < n) {
		t = m;
		m = n;
		n = t;
	}
	if (m < l) {
		t = m;
		m = l;
		l = t;
	}
	//if (m >= n...
登录查看完整内容


登录后发布评论

1 条评论
BITxzt
2020年3月24日 13:13

没问题吧 三个点不重合不共线肯定构成三角形

赞(0)