輸入 4 邊,並小到大排序
若 4 邊等長,則為正方形
若小的 2 邊等長,且大的 2 邊等長,則為長方形(矩形)
若 小的 2 邊和 < 大的 2 邊差, 則可構成 4 邊形
為什麼呢?
首先,我們將四邊形分成 2 個三角形,一個包含小的 2 邊,另一個包含大的 2 邊
假設小的 2 邊為 a b ,大的 2 邊為 c d , 且 a <= b <= c <= d
另外共同邊為 x , 則 2 三角形的邊分別為 abx 和 cdx
以小三角形的觀點來看, x < a+b
以大三角形的觀點來看, x > d - c
因此 , d - c < x < a + b => d - c < a + b
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int border[4];
int n;
while(cin >> n)
while(n--){
for(int i = 0; i<4; i++)
cin >> border[i];
sort(border,border + 4);
if(border[0] == border[1] && border[1] == border[2] && border[2] == border[3])
cout << "square\n";
else if( border[0] == border[1] && border[2] == border[3] )
cout << "rectangle\n";
else if( border[0] + border[1] > border[3] - border[2])
cout << "quadrangle\n";
else
cout << "banana\n";
}
return 0;
}