A - Higher Math
You are building a house. You'd prefer if all the walls have a precise right angle relative to the ground, but you have no device to measure angles. A friend says he has a great idea how you could ensure that all walls are upright: All you need to do is step away a few feet from the wall, measure how far away you are from the wall, measure the height of the wall, and the distance from the upper edge of the wall to where you stand. You friend tells you to do these measurements for all walls, then he'll tell you how to proceed. Sadly, just as you are done, a timber falls on your friend, and an ambulance brings him to the hospital. This is too bad, because now you have to figure out what to do with your measurements yourself.
Given the three sides of a triangle, determine if the triangle is a right triangle, i.e. if one of the triangle's angles is 90 degrees.
Input
Input starts with an integer T (≤ 200), denoting the number of test cases.
Each test case consists of three integers 1 ≤ a, b, c ≤ 40000 separated by a space. The three integers are the lengths of the sides of a triangle.
OutputFor each case, print the case number and "yes" or "no" depending on whether it's a right angle or not.
Sample Input2
36 77 85
40 55 69
Sample OutputCase 1: yes
Case 2: no
题解:很简单的判断三个数是不是勾股数的题,用勾股定理求解就行。刚开始用的勾股定理求解,一直WA,后来才发现我下意识认为第三个数为弦,其实第三个数不一定最大。后来加了一个排序函数就AC了。
#include <stdio.h>
void sort(double len[200][3],int n)
{
int i,j,k,min;
double temp;
for(i = 0;i < n;i++)
{
for(j = 0;j < 2;j++)
{
min = j;
for(k = j + 1;k < 3;k++)
{
if(len[i][k] < len[i][min])
{
min = k;
}
}
if(min != j)
{
temp = len[i][j];
len[i][j] = len[i][min];
len[i][min] = temp;
}
}
}
}
int main()
{
double len[200][3];
int n;
int i,j;
scanf("%d",&n);
for(i = 0;i < n;i++)
{
for(j = 0;j < 3;j++)
{
scanf("%lf",&len[i][j]);
}
}
sort(len,n);
for(i = 0;i < n;i++)
{
if(len[i][0] * len[i][0] + len[i][1] * len[i][1] == len[i][2] * len[i][2])
{
printf("Case %d: yes\n",i + 1);
}
else
{
printf("Case %d: no\n",i + 1);
}
}
return 0;
}