题解 | #三角形判断#
三角形判断
https://www.nowcoder.com/practice/689ec1e742394e09b1059556fc167b65
#include <stdio.h> int main() { int a = 0, b = 0, c = 0; int t = 0; while (scanf("%d %d %d", &a, &b, &c) != EOF) { if (a < b) { //将三边排序 a > b > c t = a; a = b ; b = t; } if (a < c) { t = a; a = c; c = t; } if (b < c) { t = b; b = c ; c = t; } if (a<b+c) { //三角形判定定理:任意两边之和大于第三边 --> a<b+c if (a==b&&a==c&&b==c) { //等边 printf("Equilateral triangle!\n"); } else if (a==b||a==c||b==c) { printf("Isosceles triangle!\n"); //等腰 } else { printf("Ordinary triangle!\n"); //普通 } } else { printf("Not a triangle!\n"); //非三角形 } } return 0; }