问题:输入三角形三边长,判断是否是直角三角形写出算法。
Input
The inputs start with a line containing a single integer n. Each of the n following lines contains one test case. 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.
Output
The output for every scenario begins with a line containing “Scenario #i:”, where i is the number of the scenario counting from 1. After that, output a single line containing either the string “yes” or the string “no”, depending on if the triangle in this test case has a right angle. Terminate each test case with an empty line.
Sample Input
2
36 77 85
40 55 69
Sample Output
Scenario #1:
yes
Scenario #2:
no
回答:
方法一:# include <stdio.h>
int main ()
{
int T, a, b, c ;
int nCase = 1 ;
scanf ("%d", &T) ;
while (T--)
{
scanf ("%d%d%d", &a, &b, &c) ;
if (a*a+b*b==c*c || a*a+c*c==b*b || b*b+c*c==a*a)
printf ("Scenario #%d:
yes
", nCase++) ;
else
printf ("Scenario #%d:
no
", nCase++) ;
}
return 0 ;
}
方法二:#include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
int n,a[3],pos;
while(scanf("%d",&n)!=EOF)
{
pos=0;
while(n--)
{
scanf("%d%d%d",&a[0],&a[1],&a[2]);
sort(a,a+3);
printf("Scenario #%d:
",++pos);
if(a[0]*a[0]+a[1]*a[1]==a[2]*a[2])
printf("yes
");
else
printf("no
");
}
}
return 0;
}