#include <iostream>
#include <math.h>
using namespace std;
int main(){
int a,b,c;
cin >> a >> b >> c;
if( pow(c,2) ==pow(a,2) + pow(b,2))
{
cout << "right triangle" << endl;
}
else if( pow(c,2) < pow(a,2) + pow(b,2))
{
cout<<"acute triangle"<<endl;
}
else if( pow(c,2) > pow(a,2) + pow(b,2))
{
cout << "obtuse triangle" << endl;
}
else
{
cout << "no answer" << endl;
}
return 0;
}
#include <iostream> using namespace std; int main(int argc, char** argv) { int array[4]; int buffer; while (cin >> array[1] >> array[2] >> array[3]) { //排序 for (int i = 1; i <= 2; i++) for (int j = 2; j <= 3; j++) if (array[j] < array[i]) { buffer = array[i]; array[i] = array[j]; array[j] = buffer; } int a = array[1]; int b = array[2]; int c = array[3]; if (a * a + b * b == c * c) cout << "right triangle" << endl; else if (a * a + b * b < c * c) cout << "obtuse triangle" << endl; else if (a * a + b * b > c * c) cout << "acute triangle" << endl; } //system("PAUSE"); return 0; }
附上無排序版本:
#include <cstdio> #define max(x,y,z) x>y && x>z?x:(y>z?y:z) using namespace std; int main(){ int a,b,c,mx; while(scanf("%d%d%d",&a,&b,&c)!=EOF){ mx=max(a,b,c); mx=mx*mx*2,a*=a,b*=b,c*=c; if(mx==a+b+c)printf("right triangle\n"); else if(mx>a+b+c)printf("obtuse triangle\n"); else printf("acute triangle\n"); } return 0; }其實只要a b c 分開輸入,並在每一次輸入完後比較大小就好。
不需要沒事寫這很做作的東西 ---> x>y && x>z?x:(y>z?y:z)