Programing/백준, 프로그래머스(C++)

[C++][백준4153] 직각삼각형

hye3193 2025. 1. 3. 14:42

https://www.acmicpc.net/problem/4153

 

제출 코드

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    while(true)
    {
        int num[3];
        int maxIdx = 0;
        for (int i = 0; i < 3; i++)
            cin >> num[i];
        
        if (num[0] == 0 && num[1] == 0 && num[2] == 0)
            return 0;
        
        for (int i = 1; i < 3; i++)
        {
            if (num[i] > num[maxIdx])
                maxIdx = i;
        }

        int sum = 0;
        for (int i = 0; i < 3; i++)
        {
            if (i != maxIdx)
                sum += num[i] * num[i];
        }

        if (num[maxIdx] * num[maxIdx] == sum)
            cout << "right" << '\n';
        else
            cout << "wrong" << '\n';
    }
}