Description
给三角形三条边,问这个三角形是直角,等腰,还是普通
Algorithm
先排序一下,然后判断
Code
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
void solve()
{
int a[3];
for (int i = 0; i < 3; i++)
scanf("%d", &a[i]);
sort(a, a+3);
if (a[0] * a[0] + a[1] * a[1] == a[2] * a[2])
{
puts("good");
return;
}
if (a[0] == a[1] || a[1] == a[2])
{
puts("perfect");
return;
}
puts("just a triangle");
}
int main()
{
int t;
scanf("%d", &t);
for (int i = 0; i < t; i++)
solve();
}
本博客提供了一个算法,通过输入三角形的三条边长来判断该三角形是直角、等腰还是普通三角形,并通过排序、判断条件等步骤实现这一目标。
245

被折叠的 条评论
为什么被折叠?



