判断四边形形状的。题目中只要求输入整型数据,所以定义结构体的时候用INT没用double
代码如下:
#include<iostream>
using namespace std;
struct Point{
int x,y;
Point(int x=0,int y=0):x(x),y(y){}
};
typedef Point Vector;
Vector operator + (Vector a,Vector b){return Vector(a.x+b.x,a.y+b.y);}
Vector operator - (Vector a,Vector b){return Vector(a.x-b.x,a.y-b.y);}
bool operator == (const Vector& a,const Vector& b){return a.x==b.x&&a.y==b.y;}
bool parallel(Vector a,Vector b){
return a.x*b.y==a.y*b.x;
}
int Length2(Vector a){
return a.x*a.x+a.y*a.y;
}
bool vertical(Vector a,Vector b){
if((a.x*b.x+a.y*b.y)==0)return true;
else return false;
}
int main(){
freopen("data.txt","r",stdin);
int T;
cin>>T;
int kase=0;
while(T--){
cout<<"Case "<<++kase<<": ";
Point a[5];
for(int i=0;i<4;++i){
cin>>a[i].x>>a[i].y;
}
bool can=0;
for(int i=1;i<4;++i){
Point t=a[0];
Point q=a[i];
Point r;
Point s;
if(i==1){
r=a[2];
s=a[3];
}
else if(i==2){
r=a[1];
s=a[3];
}
else if(i==3){
r=a[1];
s=a[2];
}
if(parallel(t-q,r-s)){
// cout<<i<<" zz "<<t.x<<' '<<t.y<<' '<<q.x<<' '<<q.y<<' '<<r.x<<' '<<r.y<<' '<<s.x<<' '<<s.y<<endl;
can=1;
if(parallel(s-q,r-t))can=1;
else if(parallel(r-q,s-t)){
Point tmp=r;
r=s;s=tmp;can=1;
}
else {cout<<"Trapezium"<<endl;break;}
if(vertical(t-q,s-q)&&(Length2(t-q)==Length2(s-q))){cout<<"Square"<<endl;break;}
else if(vertical(t-q,s-q)){cout<<"Rectangle"<<endl;break;}
else if(Length2(t-q)==Length2(s-q)){cout<<"Rhombus"<<endl;break;}
else {cout<<"Parallelogram"<<endl;break;}
}
}
if(!can)cout<<"Ordinary Quadrilateral"<<endl;
}
return 0;
}