7-114 3205 直角三角形

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using i32 = std::int32_t;
using i64 = std::int64_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;
using pii = std::pair<i32, i32>;
using pll = std::pair<i64, i64>;
using vi = std::vector<i32>;
using vll = std::vector<i64>;
using vpii = std::vector<pii>;
using vpll = std::vector<pll>;

void solve();

int main()
{
    std::cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}

void get_triangle(i32 a, i32 b, i32 c, i32 count)
{
    std::cout << "Triangle #" << count << '\n';
    if (a == -1)
    {
        if (b >= c)
        {
            std::cout << "Impossible.\n";
        }
        else
        {
            std::cout << "a = " << std::fixed << std::setprecision(3) << std::sqrt(c * c - b * b) << '\n';
        }
    }
    else if (b == -1)
    {
        if (a >= c)
        {
            std::cout << "Impossible.\n";
        }
        else
        {
            std::cout << "b = " << std::fixed << std::setprecision(3) << std::sqrt(c * c - a * a) << '\n';
        }
    }
    else
    {
        std::cout << "c = " << std::fixed << std::setprecision(3) << std::sqrt(a * a + b * b) << '\n';
    }
}

void solve()
{
    i32 a, b, c;
    i32 count{0};
    while (std::cin >> a >> b >> c)
    {
        if (a == 0 && b == 0 && c == 0)
        {
            return;
        }
        get_triangle(a, b, c, ++count);
        std::cout << '\n';
    }
}
posted @ 2025-10-13 16:20  TPPPP72  阅读(4)  评论(0)    收藏  举报