第一次用运算符重载,代码清晰多了。
已知两边,求组成平行四边形的第4点。运用向量相加性质。
有trick,公共点不一定是给出的第二点和第三点,自行判断。
/*************************Creater:Sevenster **Time:2012.08.01 12:05 **PID:POJ 2624 *************************/
#include <iostream>
using namespace std;class CPoint
{
public:double x, y;CPoint( double a= 0, double b= 0 ){this->x=a;this->y=b;}
};class CVector
{
public:double x, y;CVector( double a= 0, double b= 0 ){this->x=a;this->y=b;}
};CVector operator-( CPoint b, CPoint a )
{return CVector( b.x- a.x, b.y- a.y );
}CVector operator+( CVector a, CVector b )
{return CVector( a.x+ b.x, a.y+ b.y );
}void putAns( CPoint p, CPoint o, CPoint q )
{CVector A,B,C;A= p- o;B= q- o;C= A+B;printf( "%.3lf %.3lf\n", o.x+ C.x, o.y+ C.y );
}int main()
{CPoint p1,p2,p3,p4;while( scanf( "%lf %lf %lf %lf %lf %lf %lf %lf", &p1.x, &p1.y, &p2.x, &p2.y, &p3.x, &p3.y, &p4.x, &p4.y) != EOF ){if( p1.x== p3.x && p1.y== p3.y )putAns( p2,p1,p4 );else if( p1.x== p4.x && p1.y== p4.y )putAns( p2,p1,p3 );else if( p2.x== p3.x && p2.y== p3.y )putAns( p1,p2,p4 );elseputAns( p1,p2,p3 );}return 0;
}