11504: 【原1504】[Textbook]Ex3-6 三角形判断
题目
题目描述
author: 翁惠玉 张億一 万诚 白毅伟 陈乐群 原OJ链接:https://acm.sjtu.edu.cn/OnlineJudge-old/problem/1504
Description
编写一个程序,输入3个非0整数,判断以这3个值为边长是否能构成一个三角形。如果能构成一个三角形,判断这三角形是够是直角三角形。
Input Format
输入三个整数a, b, c
Output Format
- 若是直角三角形,输出
right-angled triangle
- 若非直角三角形也能构成三角形,输出
triangle
- 若不能构成三角形,输出
not triangle
Sample Input
2 3 4
Sample Output
triangle
yyong119's solution
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
double e[4];
cin >> e[1] >> e[2] >> e[3];
sort(e + 1, e + 4);
if (e[1] + e[2] <= e[3]) cout << "not triangle" << endl;
else if (e[1] * e[1] + e[2] * e[2] == e[3] * e[3]) cout << "right-angled triangle" << endl;
else cout << "triangle" << endl;
return 0;
}