Subject description
given three sides, determine what you can not form a triangle.
Description Input:
Input of data comprising a plurality of sets, each set of data comprising three positive integers a, b, c (1≤a, b, c≤10 ^ 100).
Output Description:
corresponding to each set of data, if they can form a triangle, the output "Yes"; otherwise, outputs "No".
Input example:
1 2 3
2 2 2
Output example:
No
Yes
to set up a triangle determine the conditions, learned a little elementary school mathematics knows任意两条边之和大于第三边
, but there is another way to determine任意两边之差小于第三边
, in fact, both the core idea is the same, just different forms of judgment, for examplea + b > c
, can be calleda > c - b
orb > c - a
.
Since the data is relatively large, here we use the 任意两边之差小于第三边
way of judgment.
Note: Due to a > c - b
the b > c - a
equivalent of three conditions can not write so repeat.
#include <iostream>
using namespace std;
int main() {
//注意输入范围是10^100级别,所以int、long long类型会超出
double a = 0, b = 0, c = 0;
//scanf返回值为正确输入数据的变量个数,当一个变量都没有成功获取数据时,此时返回-1
while (scanf("%lf %lf %lf", &a, &b, &c) != - 1) {
//a < b + c, b < a + c, c < b + a任意两边之和大于第三版(任意两边之差小于第三边,注意别写重复了)
//a > c - b 与 b > c - a 都是判断 a + b > c
if (a - b < c && b - c < a && c - a < b) {
printf("Yes\n");
} else {
printf("No\n");
}
}
return 0;
}