第一次用運算子多載,代碼清晰多了。
已知兩邊,求組成平行四邊形的第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 ); else putAns( p1,p2,p3 ); } return 0;}