Determine the triangle type and determine the triangle

Source: Internet
Author: User

Determine the triangle type and determine the triangle

Description
Three edges of a triangle: a, B, and c. Determine the triangle type.
About Input
The first line is the number of test data n (n <1000), followed by each row of n has three positive integers (the value cannot exceed 20000), respectively, the side length of the three sides of the triangle.
About output
For each group of input, determine the triangle type. The output "dyzj" indicates the isosceles right triangle, and "ptzj" indicates the normal right triangle. The db equilateral triangle, dyrj indicates the isosceles acute triangle, and ptrj indicates the normal acute triangle; "dydj" and "ptdj" are common blunt Triangles. "bssjx" cannot form triangles.
Example Input
23 4 530 30 30
Example output
ptzjdb
Prompt
The sum of the two shorter sides is greater than the square of the longest side. This triangle is an acute triangle;
The sum of the squares of the two shorter edges is less than the square of the longest edges. This triangle is an acute triangle;
The sum of the squares of the two shorter edges is equal to the square of the longest edges. This triangle is a right triangle.

# Include <stdio. h> # include <stdlib. h> int less (const void * p, const void * q) {int a = * (const int *) p; int B = * (const int *) q; return a-B;} int main () {int n = 0; scanf ("% d", & n); while (n --) {int a [3]; const char * p = 0; scanf ("% d", & a [0], & a [1], & a [2]); qsort (a, 3, sizeof (int), less); if (a [0] + a [1] <= a [2]) /* cannot form a triangle */{p = "bssjx ";} else {int delta = a [0] * a [0] + a [1] * a [1]-a [2] * a [2]; if (delta> 0)/* acute triangle */{if (a [0] = a [2]) p = "db "; else if (a [0] = a [1] | a [1] = a [2]) p = "dyrj"; elsep = "ptrj ";} else if (delta = 0)/* right triangle */{p = "ptzj";/* think about why you don't need to judge the right triangle at the same waist? */} Else/* if (delta <0) * // * blunt triangle */{if (a [0] = a [1]) p = "dydj "; elsep = "ptdj" ;}} printf ("% s" "\ n", p);} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.