Triangular Judgment--Niu Ke

Topic:
Link: Niuke Practice Competition
Source: Niuke.com

KiKi wants to know whether the three sides a, b, and c that have been given can form a triangle, and if they can form a triangle, determine the type of triangle (equilateral triangle, isosceles triangle or ordinary triangle).
Input: There
are multiple sets of input data for the title. Enter three a, b, c (0<a,b,c<1000) in each line as the three sides of the triangle, separated by spaces.
Output: For
each set of input data, the output occupies one line. If a triangle can be formed, an equilateral triangle will output "Equilateral triangle!", an isosceles triangle will output "Isosceles triangle!", and the remaining triangles will output "Ordinary triangle!", Otherwise, output "Not a triangle!".

Example:
Input data:
2 3 2
3 3 3
Output data:
Isosceles triangle!
Equilateral triangle!

This is a water problem. Use if to judge the relationship between the three sides to get the triangle type. But there is one place that is easy to make mistakes, that is, the type of the three-sided data. You cannot use integers like int. You have to use doubles.Floating point data, The side length may be a decimal, and there is another error-prone pointAfter judging isosceles, you need to judge whether it can form a triangle, Cannot simply be equal to the two sides is an isosceles triangle.

#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
    
    
 double a,b,c;
 while(scanf("%lf %lf %lf",&a,&b,&c)!=EOF)
 {
    
    
  if(a==b||b==c||a==c)
  {
    
    
   if(a==b&&b==c)
   {
    
    
    cout<<"Equilateral triangle!"<<endl;
   }
   else if(a+b>c&&b+c>a&&a+c>b){
    
    
    cout<<"Isosceles triangle!"<<endl;
   }
   else {
    
    
    cout<<"Not a triangle!"<<endl;
   }
  }
  else {
    
    
   if(a+b>c&&b+c>a&&a+c>b)
   {
    
    
    cout<<"Ordinary triangle!"<<endl;
   }
   else {
    
    
    cout<<"Not a triangle!"<<endl;
   }
  }
 }
 return 0;
}

Guess you like

Origin blog.csdn.net/HT24k/article/details/107149320