#include <bits/stdc++.h>
using namespace std;
struct node {
int x,y;
bool operator<(const node T)const {
if(x!=T.x)return x<T.x;
return y<T.y;
}
};
int getlen(node a,node b) {
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
bool check(node a[]) {
sort(a,a+4);
int s[10];
s[1]=getlen(a[0],a[1]);
s[2]=getlen(a[0],a[2]);
s[3]=getlen(a[0],a[3]);
s[4]=getlen(a[1],a[2]);
s[5]=getlen(a[1],a[3]);
s[6]=getlen(a[2],a[3]);
sort(s+1,s+1+6);
return s[1]==s[4]&&s[5]==s[6];//对角线相等就可以了,double类型应该也是一样的
}
int main() {
node a[4];
for(int i=0;i<4;i++)cin>>a[i].x;
for(int i=0;i<4;i++)cin>>a[i].y;
if(check(a))cout<<"It's a square";
else cout<<"Not a square";
return 0;
}
标签:std,node,判断,struct,int,namespace,正方形
From: https://www.cnblogs.com/basicecho/p/17003142.html