http://acm.hdu.edu.cn/showproblem.php?pid=2393
判断输入的几条边是否能组成一个直角三角形,但输入的数字中c不一定为最大,即斜边,需要先判断长短,或者在平方和中去判断也可以
View Code
1 #include<iostream> 2 #include<stdlib.h> 3 using namespace std; 4 struct angle 5 { 6 double a; 7 double b; 8 double c; 9 }; 10 int main() 11 { 12 int n,i; 13 angle g[10000]; 14 cin>>n; 15 for(i=0;i<n;i++) 16 cin>>g[i].a>>g[i].b>>g[i].c; 17 for(i=0;i<n;i++){ 18 cout<<"Scenario #"<<i+1<<":"<<endl; 19 if((g[i].a*g[i].a+g[i].b*g[i].b==g[i].c*g[i].c)||(g[i].a*g[i].a+g[i].c*g[i].c==g[i].b*g[i].b)||(g[i].c*g[i].c+g[i].b*g[i].b==g[i].a*g[i].a)) 20 cout<<"yes"<<endl; 21 else 22 cout<<"no"<<endl; 23 cout<<endl; 24 } 25 system("pause"); 26 return 0; 27 }