三角形的判断:两边之和大于第三边,两边之差小于第三边...
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
bool judge1(int x[])
{
for(int i=2;i<4;++i)
{
if(x[i-2]+x[i-1]>=x[i])
{
return 1;
}
}
return 0;
}
bool cheak(int a,int b,int c)
{
return a+b>c&&a-b<c;
}
bool judge2(int x[])//判断能否组成三角形
{
for(int i=2;i<4;++i)
{
if(cheak(x[i-2],x[i-1],x[i]))//三角形
{
return 1;
}
}
return 0;//钝角
}
bool judge3(int x[])
{
for(int i=0;i<4;++i)
{
for(int j=i+1;j<4;++j)
{
for(int k=j+1;k<4;++k)
{
if(x[i]+x[j]==x[k])//组成线段
{
return 1;
}
}
}
}
return 0;//钝角
}
int main()
{
int x[4];
while(~scanf("%d%d%d%d",&x[0],&x[1],&x[2],&x[3]))
{
sort(x,x+4);
if(!judge1(x))//不能组成三角形
{
printf("IMPOSSIBLE\n");
continue;
}
if(judge2(x))
{
printf("TRIANGLE\n");
continue;
}
if(judge3(x))
{
printf("SEGMENT\n");
}
}
return 0;
}