yiyi:判断能不能组成三角形,可以通过两边之和大于第三边来判断,但我这道题是用两边之和大于最大的那条边来判断的。还有一个要注意的地方是,题目中有说三个数是正数,所以要用float 或 double 来定义,不能用int .就因为这个害我提交了好几遍呢。
Description
给定三条边,请你判断一下能不能组成一个三角形。
Input
输入数据第一行包含一个数M,接下有M行,每行一个实例,包含三个正数A,B,C。其中A,B,C <1000;
Output
对于每个测试实例,如果三条边长A,B,C能组成三角形的话,输出YES,否则NO。
Sample Input
2 1 2 3 2 2 2
Sample Output
NO YES
#include <stdio.h>
int main () {
int m;
double a, b, c, max, term;
scanf("%d", &m);
while (m--) {
scanf("%lf %lf %lf", &a, &b, &c);
max = a;
if (max < b){
term = max;
max = b;
b = term;
}
if (max < c) {
term = max;
max = c;
c = term;
}
if (max < b + c)
printf("YES\n");
else printf("NO\n");
}
return 0;
}